Getting into VBA in Visio without a course

P

Paul

I come from a C++ background, and without actually taking VBA, I’m
cobbling together code from the web to change attributes of selected
shapes, lines, and associated text. I’m trying to reconcile the
difference in coding style between the following two code pieces for
changing a line from dashed to solid:

1. From the Web
------------------
Public Sub SelectAllDashed()
Dim shp As Shape
Visio.ActiveWindow.DeselectAll
For Each shp In Visio.ActivePage.Shapes
If shp.OneD Then
If shp.Cells("LinePattern") = 23 Then
shp.Cells("LinePattern") = 1
End If
End If
Next shp
End Sub

2. From Macro Recording
---------------------------
Sub Palette2()
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Line Properties")

Application.ActiveWindow.Page.Shapes.ItemFromID(7).CellsSRC(visSectionObject,
visRowLine, visLinePattern).FormulaU = "1"
Application.EndUndoScope UndoScopeID1, True
End Sub

I understand that there are differences in control flow structure due
to the fact that #1 searches for dashed lines, while #2 just sets a
line pattern. However, the difference between the statements that
actually assigns the line pattern “1” is quite pronounced. Some of it
is due to the fact that “shp” in #1 already has
“Visio.ActivePages.Shapes” implied, but the rest of the line is still
simpler in #1. Is it preferrable to use #1?

Further complicating the deciphering of #2’s pattern assignment line
is the fact that the words don’t match readily with what I see in the
ShapeSheet. Without learning the entire schema of Visio, what is the
best strategy for using Macro Recording to pull out the details that I
might want to use in my own code?

Thanks.
 
A

AlEdlund

Macro capture tends to be more "atomic" in that it uses the deeper (less
symbolic) definitions. You'll notice in the macro version that the actions
are wrapped in undo scopes, where the web examples are just that - examples.
IMHO it is a good thing to watch how the macro recorder does the detail
implementation, while understanding that in your implementation might want
to generalize things like the concept of "ItemFromID(7)".
al

I come from a C++ background, and without actually taking VBA, I’m
cobbling together code from the web to change attributes of selected
shapes, lines, and associated text. I’m trying to reconcile the
difference in coding style between the following two code pieces for
changing a line from dashed to solid:

1. From the Web
------------------
Public Sub SelectAllDashed()
Dim shp As Shape
Visio.ActiveWindow.DeselectAll
For Each shp In Visio.ActivePage.Shapes
If shp.OneD Then
If shp.Cells("LinePattern") = 23 Then
shp.Cells("LinePattern") = 1
End If
End If
Next shp
End Sub

2. From Macro Recording
---------------------------
Sub Palette2()
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Line Properties")

Application.ActiveWindow.Page.Shapes.ItemFromID(7).CellsSRC(visSectionObject,
visRowLine, visLinePattern).FormulaU = "1"
Application.EndUndoScope UndoScopeID1, True
End Sub

I understand that there are differences in control flow structure due
to the fact that #1 searches for dashed lines, while #2 just sets a
line pattern. However, the difference between the statements that
actually assigns the line pattern “1” is quite pronounced. Some of it
is due to the fact that “shp” in #1 already has
“Visio.ActivePages.Shapes” implied, but the rest of the line is still
simpler in #1. Is it preferrable to use #1?

Further complicating the deciphering of #2’s pattern assignment line
is the fact that the words don’t match readily with what I see in the
ShapeSheet. Without learning the entire schema of Visio, what is the
best strategy for using Macro Recording to pull out the details that I
might want to use in my own code?

Thanks.
 
W

WapperDude

Paul --
I ran across the following post in the New Users section of the Visio forum.
John's reply might be of interest, he basically transforms a macro and
eliminates the "undo's".

Hope this helps.
Wapperdude
 

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