Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating WORDART/CHART objects in MSWORD via VB

Status
Not open for further replies.

zakman

Programmer
Aug 15, 2001
49
US
I have a MSWORD2000 document that contains a WordArt object (just some pretty text) and a simple Chart object. I am using Visual Basic 6.0 to automate MSWORD and insert some data.

However, there are instances where I would like to hide the WordArt object (I would even consider deletion as an alternative). Does anyone know how to reference this object in MSWORD's object model?

Aside, I have a chart in this same document that I need to reference... any shortcuts on accessing the chart object from VB?

Thanks in advance,
Kevin
 
I hope I can be helpful by not helping... :)

Don't forget that a lot of the time you can figure out how to reference an object (or accomplish some task) by choosing "Tools/Macros/Record New Macro" and actually doing whatever you want to accomplish, and then hit alt-f11 and go see what sort of code the Office application put together.

It's not necessarily elegant, and Office has a habit of throwing in a LOT of extraneous code (try recording a page set-up in Excel), but it works. Oh, and Office doesn't use any nice tricks that will speed up your code (like using With/End With). But again, it works.
 
WordArt objects are shapes in the word objectmodel.
Give the wordart object a name and loop through the shapes-collection of the document.
For Each ThisSection In ActiveDocument.Sections
Set WorkRange = ActiveDocument.Range( _
Start:=ThisSection.Range.End - 1, _
End:=ThisSection.Range.End - 1)

For Each ThisHeader In WorkRange.Sections(1).Footers
If ThisHeader.LinkToPrevious = False Then
Set HdrRange = ThisHeader.Range

'when HdrRange.shaperange is not available
On Error GoTo ErrorHandler
If HdrRange.ShapeRange.Count > 0 Then
For Each aShape In HdrRange.ShapeRange
If InStr(aShape.Name, KISMARKER) > 0 Then
aShape.Delete
End If
Next aShape
End If
End If
Next ThisHeader
next ThisSection
 
I tried the approach of recording a macro when changing
the value of a datasheet cell. However, it seems that
the 'recording' stops when you have selected the datasheet.

Good idea though, I might use it in other situations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top