Accessing Visio drawing from Word

R

Ruud

I want to access all Visio drawings in a Word document and from there
enumerate all shapes in that drawing. I am able to access the Visio
drawings but can't get any thing from the object.
I have found some sample programs which uses Dim xx As Visio.Document,
but that doesn't work in my case (Word 2003).

All suggestions are welcome.
 
J

John... Visio MVP

Ruud said:
I want to access all Visio drawings in a Word document and from there
enumerate all shapes in that drawing. I am able to access the Visio
drawings but can't get any thing from the object.
I have found some sample programs which uses Dim xx As Visio.Document,
but that doesn't work in my case (Word 2003).

All suggestions are welcome.


To start with, even though both are Office apps, Word knows nothing about
Visio. You need to add a reference to the Visio object model into Word's VBA
environment.

What you ask is far from trivial, so can I ask what your ultimate goal is?

Would adding a legend to the Visio drawing and treating the Visio drawing as
a seperate entry within the Worddocument meet your needs? The legend can be
used as the reference between the two "documents"

John... Visio MVP
 
R

Ruud

To start with, even though both are Office apps,Wordknows nothing aboutVisio. You need to add a reference to theVisioobject model intoWord'sVBA
environment.

What you ask is far from trivial, so can I ask what your ultimate goal is?

Would adding a legend to theVisiodrawingand treating theVisiodrawingas
a seperate entry within the Worddocument meet your needs? The legend can be
used as the reference between the two "documents"

John...VisioMVP

The objective is to retrieve all texts from the drawing for
translation (automatic or with some manual process). After that has
been done, I would like to put the translated texts back in the
(embedded) Visio drawing. The process of translation (possibly in
Excel) is rather simple, but getting access to the text (both for
reading and writing) is my problem.

In effect if I could do some thing like Visio.Document.Shapes.Count
and Visio.Document.Shapes.Text(I) that would be the solution. But as I
said, Word doesn't know about Visio (objects).
Can you help me with that?

Ruud.
 
J

John... Visio MVP

Ruud said:
The objective is to retrieve all texts from the drawing for
translation (automatic or with some manual process). After that has
been done, I would like to put the translated texts back in the
(embedded) Visio drawing. The process of translation (possibly in
Excel) is rather simple, but getting access to the text (both for
reading and writing) is my problem.

In effect if I could do some thing like Visio.Document.Shapes.Count
and Visio.Document.Shapes.Text(I) that would be the solution. But as I
said, Word doesn't know about Visio (objects).
Can you help me with that?

Ruud.


I would leave Word out of the equation and just run the code from Visio.

How are you doing the translation?

One thing to note is that Visio shapes can contain shape collections. So
even though there is only one text block per shape, a shape can contain a
collection of shape each of which can contain a text block.

Public Sub Display_Text()

Dim PagObj As Visio.Page
Dim shpObj As Visio.Shape

For Each PagObj In ActiveDocument.Pages
For Each shpObj In PagObj.Shapes
process_shp shpObj
Next
Next PagObj

End Sub
Public Sub process_shp(shp As Visio.Shape)
Dim subShp As Visio.Shape

Debug.Print shp.Name; " "; shp.Text; " "; shp.Shapes.Count

If shp.Shapes.Count > 0 Then
For Each subShp In shp.Shapes
process_shp subShp
Next subShp
End If

End Sub




John....
 
R

Ruud

I would leaveWordout of the equation and just run the code fromVisio.

How are you doing the translation?

One thing to note is thatVisioshapes can contain shape collections. So
even though there is only one text block per shape, a shape can contain a
collection of shape each of which can contain a text block.

Public Sub Display_Text()

Dim PagObj AsVisio.Page
Dim shpObj AsVisio.Shape

For Each PagObj In ActiveDocument.Pages
    For Each shpObj In PagObj.Shapes
      process_shp shpObj
  Next
Next PagObj

End Sub
Public Sub process_shp(shp AsVisio.Shape)
Dim subShp AsVisio.Shape

Debug.Print shp.Name; " "; shp.Text; " "; shp.Shapes.Count

If shp.Shapes.Count > 0 Then
    For Each subShp In shp.Shapes
        process_shp subShp
    Next subShp
End If

End Sub

John....- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

John,

Running the code from Visio is not an option to me, because the Visio
drawings are contained in a Word document. In fact, I have already a
Visio program to do my translations on a Visio drawing (file), but I
need to it for a Word doucment with embedded Visio drawings.

If there is a possibility to access these from Visio, that would be
great, but I'm afraid that's even more complex.

Do you have any suggestions?

Ruud.
 
J

John... Visio MVP

I would leaveWordout of the equation and just run the code fromVisio.

How are you doing the translation?

One thing to note is thatVisioshapes can contain shape collections. So
even though there is only one text block per shape, a shape can contain a
collection of shape each of which can contain a text block.

Public Sub Display_Text()

Dim PagObj AsVisio.Page
Dim shpObj AsVisio.Shape

For Each PagObj In ActiveDocument.Pages
For Each shpObj In PagObj.Shapes
process_shp shpObj
Next
Next PagObj

End Sub
Public Sub process_shp(shp AsVisio.Shape)
Dim subShp AsVisio.Shape

Debug.Print shp.Name; " "; shp.Text; " "; shp.Shapes.Count

If shp.Shapes.Count > 0 Then
For Each subShp In shp.Shapes
process_shp subShp
Next subShp
End If

End Sub

John....- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

John,

Running the code from Visio is not an option to me, because the Visio
drawings are contained in a Word document. In fact, I have already a
Visio program to do my translations on a Visio drawing (file), but I
need to it for a Word doucment with embedded Visio drawings.

If there is a possibility to access these from Visio, that would be
great, but I'm afraid that's even more complex.

Do you have any suggestions?

Ruud.


I have not tried it, but it may be possible to do it to a Visio drawing
within Word.

If you are using Word, you can control Visio through Word's VBA, but you
have to include a reference to the Visio object model in the Word VBA
environment and make sure you fully qualify references so you do not confuse
VBA. (Both Visio and Word have Shapes).

John...
 

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