Visio Guy

Visio Discussions => General Visio => Topic started by: tinsley207 on April 21, 2015, 03:36:51 PM

Title: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 21, 2015, 03:36:51 PM
Hello All!  New to the forum!  And relatively new to VISIO!  I'm using Visio 2013 and I'm a huge keyboard user.  I like to have keystrokes or even macros for as many things as possible.  I do a lot of signal flow path drawings and I am ALWAYS adding a "Arrow at END" on my connector lines.  I'm really tired of selecting the ARROWS tool then navigating down to the "Arrow at end" and clicking.  It just takes too long. I want to be able to draw the connector using the connector tool and then hit F2 and BANG have visio drop the arrow at the end of the line!  Can I do this?  I will mention that I've already done some macro work with my Microsoft Keyboard but what I really would need is the actual menu items etc to do what I want and I just can't seem to find that.  Please help!

Nate

Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Yacine on April 21, 2015, 04:05:44 PM
Hi Nate,
no need for a macro.
Set up a template fromwhich you will start every time.
Draw a connector, set its line ends to whatever you want, drag it in the page stencil. save, close, done.
Next time you create a new drawing from the template, all your connectors will have the settings, you prepared in the template.
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 21, 2015, 04:15:33 PM
That's nice but not all my connectors have arrows.  Also what is the PAGE STENCIL?  Is that the shape stencil column typically on the left?
Thanks
Nate
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Yacine on April 21, 2015, 04:25:10 PM
Hi Nate,
The small link beneath the actual message is an attachment. LeftMouseClick on Link and Download. Goto Downloads and test. ;D
... and I gave you that advice, because you explicitely wrote "ALWAYS adding ...".
So I understand that this is an "almost" ALWAYS.  ;)
In this case , you'll stay with the template, but need to add an according macro to it.
Record a macro in which you'll format properly the connector, assign it to the keyboard shortcut of your choice and save as template.
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 21, 2015, 09:56:03 PM
Hi Yacine,

Well your cool drawing works but of course it's for EVERY connector!  Yes I guess I should have been more specific!  It's not EVERY connector but ALMOST.  So I started in on the other idea with the macro.  I've never recorded a macro before but I made a template called 11x17default.vst.  I made a simple connector line, then I recorded a new macro using CTRL+Q for the shortcut, and clicked the arrow at end button and chose my style.  Then I stopped the macro.  I saved the document and it wanted to be a VSTM so I did that.  Now when I open the template I get a warning about macros, so I said ENABLE Macros.  I drew a line and pressed CTRL+Q..... nothing.  I closed visio and reopened, then opened the template.  This time I went into macro security and enabled all macros(not recommended) but still nothing when I press CTRL+Q.  What am I missing here?  Thanks.

Nate
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Surrogate on April 22, 2015, 04:09:21 AM
Hi, Nate!
You first time tried record macro via recorder, and after enable macros abilities?
Press keys Alt+F11,  can you see some code in Module1?

I am haven't there PC with  visio, but i think you MUST enable macros BEFORE
you start play with macrorecorder. On my PC macro ALWAYS enable!

Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Yacine on April 22, 2015, 04:53:22 AM
With Ctrl-F11 you can open the Visual Basic Editor (VBE).
Can you post the code displayed in the recorded macro?
You could also upload the visio template, but please as Visio 2007 version, as I cannot open versions above.
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Surrogate on April 22, 2015, 09:08:15 AM
Quote from: Yacine on April 22, 2015, 04:53:22 AM
With Ctrl-F11 you can open the Visual Basic Editor (VBE).
Yacine, but with Ctrl+F11 you open window for change texts tabs :)

Nate, check your macro options
Press Alt+F8
(http://visio.getbb.ru/gallery/image.php?pic_id=148)
(http://visio.getbb.ru/gallery/image.php?pic_id=149)
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Surrogate on April 22, 2015, 09:25:53 AM
oh, i see !!!
when you user macrorecorder it write line like is
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "4"
this code can change only shape with ID = 1.
Quote from: tinsley207 on April 21, 2015, 09:56:03 PM
I drew a line and pressed CTRL+Q..... nothing. 
your new drawed line can't have ID = 1.
you must modify your macro, for example
Sub Macro1()
' Keyboard Shortcut: Ctrl+q
'
Dim sh As Shape
Set sh = ActiveWindow.Selection(1)
sh.CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "4"
End Sub

Quote from: wapperdude on April 15, 2015, 05:27:04 PM
  Bring up the macros window (Alt+F8) or Tools>macros.  Select (high light) the macro from the list and then press Options...  Enter the desired key in the box.  That's it.
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Yacine on April 22, 2015, 04:17:53 PM
Quote from: Surrogate on April 22, 2015, 09:08:15 AM
Yacine, but with Ctrl+F11 you open window for change texts tabs :)

Right I meant the other CTRL: "ALT" ;)
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 22, 2015, 08:05:52 PM
I double checked my macro options and I do have "q" in the appropriate box.  Here is my macro


Sub Arrow()
'
' Adds ARROW at END to the end of a line.
'
' Keyboard Shortcut: Ctrl+q
'

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Line Ends")
    Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "13"
    Application.EndUndoScope UndoScopeID1, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: Surrogate on April 22, 2015, 09:22:24 PM
Hi, Nate ! did you see this message ?
Quote from: Surrogate on April 22, 2015, 09:25:53 AM
oh, i see !!!
when you user macrorecorder it write line like is
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "4"
i am guess  ;)
Quote from: tinsley207 on April 22, 2015, 08:05:52 PM
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowLine, visLineEndArrow).FormulaU = "13"
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 23, 2015, 07:00:22 PM
OK Surrogate you're going to have to be more clear.  What should my macro say?
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: wapperdude on April 23, 2015, 07:47:40 PM
Surrogate did, see reply #8, i.e., use selection(1) syntax.  This refers to the 1st (only) selected item, not to a specific shape.

Wapperdude
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 23, 2015, 08:57:53 PM
Wapperdude I am BRAND NEW to macros.  Can you please show me in my macro where the edit needs to take place?  I've looked at the code in reply 8 and I'm sorry but I just don't see where the code needs to change!! Help!
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: wapperdude on April 23, 2015, 10:16:13 PM
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
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: tinsley207 on April 24, 2015, 02:50:44 PM
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? 
Title: Re: Keyboard shortcut for RIGHT ARROW END!
Post by: wapperdude on April 24, 2015, 03:25:02 PM
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