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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|