A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Visio
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Getting into VBA in Visio without a course



 
 
Thread Tools Display Modes
  #1  
Old July 22nd, 2008, 07:41 PM posted to microsoft.public.visio.general
Paul
external usenet poster
 
Posts: 406
Default Getting into VBA in Visio without a course

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.
  #2  
Old July 22nd, 2008, 09:29 PM posted to microsoft.public.visio.general
AlEdlund
external usenet poster
 
Posts: 468
Default Getting into VBA in Visio without a course

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

"Paul" wrote in message
...
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.

  #3  
Old July 26th, 2008, 02:39 AM posted to microsoft.public.visio.general
WapperDude
external usenet poster
 
Posts: 589
Default Getting into VBA in Visio without a course

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



"Paul" wrote:

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.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:41 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.