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?>>>)

Re: Proper coding of AddOLEObject by Jezebel

Jezebel
Mon Aug 22 16:00:27 CDT 2005

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





"Bill Sturdevant" <BillSturdevant@discussions.microsoft.com> wrote in
message news:EDBF08FF-77CB-484B-94A3-BA41BF1EE295@microsoft.com...
>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?>>>)
>