Keyboard shortcut for RIGHT ARROW END!

Started by tinsley207, April 21, 2015, 03:36:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

#15
Sure, not a problem. 

From above, your code has this line, generated by the macro recorder:
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "13"

This specifically works with shape ID =1, namely, sheet.1.  However, you want to work with any shape that you select.  Note, the assumption is that only one shape at a time is selected.  The new syntax becomes

Application.ActiveWindow.Selection(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "13". 

Typically, the "Application" can be dropped or "may be substituted with Visio".  Thus, your code would become
ActiveWindow.Selection(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "13". 

or as per Surrogate:
Dim sh As Shape
Set sh = ActiveWindow.Selection(1)
sh.CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "13"


where Surrogate declared a variable, "sh", as a shape object, which he then set equal to ActiveWindow.Selection(1).   This further condenses the code line in question.  However, it's not necessary to use a variable, unless your code would have multiple lines employing such a variable.

HTH
wapperdude
Visio 2019 Pro

tinsley207

AWESOME!!!  :) IT is WORKING! Thanks WAPPERDUDE! Now just before we let this go, I noticed that you said this works for one line at time and that's great and I'm very happy!  But what about if I did want to select two lines and have it work?  Is that what surrogate's code allows? 

wapperdude

For multiple selections you need to incorporate a loop structure.  Basically, do something until finished.  In VBA there are several types of loop structures.  Using Surrogate's approach isn't required.

For your scenario you would make your selections.  Could be 1 or more, say, up to "n" selections.  Next, set the loop to iterate n times.  The line of code that has ActiveWindow.Selection(1)....would be modified to be ActiveWindow.Selection(i)...
The "i", allows the code to go thru each selected line shape.  It is numerically advanced each time the loop iterates.

You may want to Google for  (or while) loops to see how they look, work.

Wapperdude
Visio 2019 Pro