Results 1 to 2 of 2

Thread: Creating a MSGraph in Word

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Cleveland, OH
    Posts
    33

    Creating a MSGraph in Word

    The code below works fine, if I wanted to open up a new document, insert a graph, and formatt it as needed. However I would like to use a template which then would contain all relative formatting and would only require data values to be updated. However from Word once I put the graph object into edit mode I cannot determine how to insert the new data values or to put it another way I cannot get a pointer to the MSGraphChart.

    Thank You

    '** Works for a new document and new chart


    Dim oWordApp As Word.Application
    Dim oWordDoc As Word.Document
    Dim r As Integer, c As Integer
    Dim oShape As Word.Shape
    Dim oGraphChart As Graph.Chart

    'Create a new document in Word.

    Set oWordApp = CreateObject("Word.Application")
    oWordApp.Visible = True
    Set oWordDoc = oWordApp.Documents.Add

    'Add some text to the document.
    oWordDoc.Content.Text = "This is my new chart:"

    'Embed a chart on the document.
    Set oShape = oWordDoc.Shapes.AddOLEObject(Left:=100, Top:=100, Width:=350, Height:=200, _
    ClassType:="MSGraph.Chart", DisplayAsIcon:=False)
    Set oGraphChart = oShape.OLEFormat.Object

    Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
    With oGraphChart

    '*** Graph commands
    End With


    '** Where I am at

    Dim oWordApp As Word.Application
    Dim oWordDoc As Word.Document
    Dim r As Integer, c As Integer
    Dim oShape As Word.Shape
    Dim oGraphChart As Graph.Chart

    'Create a new document in Word.

    Set oWordApp = CreateObject("Word.Application")
    oWordApp.Visible = True
    Set oWordDoc = oWordApp.Application.Documents.Open(App.Path & "\report_path\assessment.doc")
    '**** Set oWordDoc = oWordApp.Documents.Add

    'Add some text to the document.
    '**** oWordDoc.Content.Text = "This is my new chart:"

    'Embed a chart on the document.
    '*** Set oShape = oWordDoc.Shapes.AddOLEObject(Left:=100, Top:=100, Width:=350, Height:=200, _
    '**** ClassType:="MSGraph.Chart", DisplayAsIcon:=False)
    '**** Set oGraphChart = oShape.OLEFormat.Object

    '*** Puts the graph object into edit mode
    Set oShape = ActiveDocument.Shapes("Object 2").Edit

    Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
    With oGraphChart

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Cleveland, OH
    Posts
    33

    Thumbs up

    Sometimes you get lucky and sometimes you just need to step away from the problem for a bit. The missing/needed code needed (for anyone intrested) after opening up the Word templates is


    oWordDoc.Application.ActiveDocument.Shapes("object 2").Activate
    Set oGraphChart = oWordDoc.Application.ActiveDocument.Shapes("object 2").OLEFormat.Object

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width