Convert from VBA (macro) to VB

C

Caroline

I have a macro written in VBA in a Visio file.
I want to convert it to a standalone executable VB file.
Is it feasable?

Dim PathFileName As String
PathFileName = "C:\VisioFile.vsd"
Set VApp = CreateObject("Visio.Application")
Set VDoc = VApp.Documents.Open(PathFileName)
'how to test if previous statement executed flawlessly?
Set ActiveDocument = VDoc
MsgBox "Name: " & Name
MsgBox "ActiveDocument.Name: " & ActiveDocument.Name

So far so good

Dim Shap As Visio.Shape
-> Compile error: User-defined type not defined

For Each AShape In ActivePage.Shapes
MsgBox AShape.ID
Next AShape

1 - How can I declare Visio types in plain VB?
2 - How can I set the default 'container' to the Visio file,
and not the VB application?
Ie., I want Name to returns the Visio file's name,
and not the VB application's name.

Thank you
 
A

Al Edlund

within your vb compiler, have you referenced the visio typelib?

have you considered using the with 'function' i.e.

with Vdoc
msgbox "Name: " & .Name
end with

al
 
C

Caroline

Al Edlund said:
within your vb compiler, have you referenced the visio typelib?
No, not yet.
I was looking for a #include thing for VB...
Can you please provide me the complete statement?
Thank you
 
A

Al Edlund

in my ms vb6 compiler, I go to projects => references and then pick the
file. I don't use an include statement.
Sorry,
Al
 
C

Caroline

Thank you Al Edlund for your help.

Now, on the line
For Each AShape In ActivePage.Shapes

I am getting the following error:
Run-time error '429'
ActiveX component can't create object

What is wrong?
Is there any DLL file I should register?


Al Edlund said:
in my ms vb6 compiler, I go to projects => references and then pick the
file. I don't use an include statement.
Sorry,
Al

That is still returning Name: Form1
 
C

Caroline

Error 429, ActiveX component can't create object

(for those who read my previous post before I delete it)

That's because 'Set ActiveDocument = VDoc
was commented out
and ActiveDocument.Shapes made no sense in this context.

Please disregard my previous post
 
C

Caroline

Thank you Al Edlund for your reply;
Now, how can I access the shapes in the opened Visio file???

something (that works) like :
Set Vdoc = VApp.Documents.Open(PathFileName)
If Err = 0 Then
Vdoc.Activate

Dim AShape As Visio.Shape
Dim pageObj As Visio.Page
Set pageObj = ThisDocument.Pages(1)
Set pageObj = pageObj.Pages(1)

For Each AShape In pageObj.Shapes
MsgBox AShape.ID
Next AShape

....?
 
A

Al Edlund

When I chase objects in a document I use something like this

Set objPages = visDocument.Pages

For iPagCtr = 1 To objPages.Count
'Debug.Print "start page " & iPagCtr

Set objPage = objPages(iPagCtr)
'Debug.Print objPage.Name
If objPage.Background = False Then
For iObjCnt = 1 To objPage.Shapes.Count
Set objShape = objPage.Shapes(iObjCnt)
' do something with the object that you've just
selected
debug.print objShape.Name
next iObjCnt
end if
next iPagCtr


al
 

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