Failure to access Word Graph using VBA

M

MartinR

I'm trying to update data in an embedded Graph object using VBA in a Word
2007. I can access the data in the graph manually, but the Graph data
structure is not loaded in the data structure and the VBA code fails to
locate the OLEFormat object of the InlineShape.

Any thoughts?

Code follows:

Dim oMSGraphWrapper As Word.InlineShape
Set oDoc = ActiveDocument
oDoc.Application.ScreenUpdating = False
Set oMSGraphWrapper = oDoc.InlineShapes(1)

Set oMSGraphObject = oMSGraphWrapper.OLEFormat.Object <<<<<<<------
FAILS HERE; i.e. OLEFormat = NULL


Set oDataSheet = oMSGraphObject.Application.DataSheet

With oDataSheet
.Range("b2").Value = 10
.Range("b3").Value = 20
.Range("c2").Value = 100
.Range("c3").Value = 200
End With

With oMSGraphObject.Application
.Update
.Quit

.....ETC
 
D

Doug Robbins - Word MVP

You may be coming up against the issue whereby if
a Word 2003 document that contains a link such as:

LINK Excel.Sheet.8 "C:\\Documents and
Settings\\dROBBINS\\Local Settings\\Temporary Internet
Files\\OLK4FD\\CER ERS-92 forecast cashflow data.xls"
"Sheet1!R1C6:R11C10" \a \p

is saved as a .docx or docm file and then closed and
re-opened, the link will have changed to:

LINK Excel.Sheet.8 "C:\\Documents and
Settings\\dROBBINS\\Local Settings\\Temporary Internet
Files\\OLK4FD\\CER ERS-92 forecast cashflow
data.xls!Sheet1!R1C6:R11C10" "" \a \p

Note that the:

xls" "Sheet

has been changed to

xls!Sheet

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

MartinR

I'm using Office2007 and the graph has been taken from an Access application.

The OLEFormt field is not-null if I create a new graph instance within WORD.
But if I copy the instance from MSAccess it is not accessible from VBA. Is
this a compatibility issue? I've checked that all references are to version
12 of the application libraries.
 
D

Doug Robbins - Word MVP

Looking at the VBA help file for the OLEFormat property of an InLineShape, I
see that it represents the OLE characteristics (other than linking) for the
specified inline shape.

If what you are wanting to do is access the source of the OLEObject, then I
believe that you should be using the .Field.Code.Text attribute of the
InlineShape.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

MartinR

Sorry that field is also set to NOTHING.



Doug Robbins - Word MVP said:
Looking at the VBA help file for the OLEFormat property of an InLineShape, I
see that it represents the OLE characteristics (other than linking) for the
specified inline shape.

If what you are wanting to do is access the source of the OLEObject, then I
believe that you should be using the .Field.Code.Text attribute of the
InlineShape.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

That would indicate to me that you are not dealing with an OLEObject (That
is an object with a link to it's source) but rather an object that is
embedded in the document.

With an OLEObject, if I run

MsgBox ActiveDocument.InlineShapes(1).Field.Code.Text it returns the text
for a LINK field.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
T

Tony Jollans

It's a while since I've done this and, if I recall, you can't do everything
you might want to. That said, I think what you have to do is activate the
object - OLEFormat.DoVerb(1) or something similar - to instantiate an
MSGraph object to work with.
 

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