Proper coding of AddOLEObject

B

Bill Sturdevant

I am trying to use VBA code to enter a line of text, and then add an MSGraph
Chart on the very next line, anchored to the text. I am using the following
code, but need to know what to use for the Anchor property:

Selection.TypeText Text:="My text goes here"
Selection.TypeParagraph
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
Dim oShape As Word.Shape
Set oWordApp = GetObject(, "Word.Application")
Set oWordDoc = ActiveDocument
'Embed a chart on the document.
Set oShape = oWordDoc.Shapes.AddOLEObject( _
Width:=150, Height:=150, _
ClassType:="MSGraph.Chart", DisplayAsIcon:=False, _
Anchor:=<<<WHAT GOES HERE?>>>)
 
J

Jezebel

I think you've picked up some snippets of code from other sources without
understanding them. If you're writing code in Word VBA, you don't need to
instantiate an instance of Word: you're already in one!

Selection.TypeText Text:="My text goes here"
ActiveDocument.Shapes.AddOLEObject Width:=150, _
Height:=150, _
ClassType:="MSGraph.Chart", _
DisplayAsIcon:=False, _
Anchor:=Selection.Paragraphs(1).Range
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top