Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

creating a visio 2003 button add-on using VSTO with Visual Studio

0 views
Skip to first unread message

Biggaford

unread,
Dec 12, 2008, 2:43:05 PM12/12/08
to
I need some guidance in creating a button (to perform an action) on a visio
toolbar or menu when visio starts up (code to be placed in the start up sub
of the add-in), could someone help in directing me to a good source on how
this may be accomplished or provide some basic code for a start.

using Visio 2003 professional, windows xp.
.NET framework 2.0


The code below has steps i think is involve, but please confirm if i have
the correct approach. This was a test to disable a menuitem.

Thanks.


Dim menuUIObject As Visio.UIObject
Dim menuMenuSets As Visio.MenuSets
Dim menuMenuSet As Visio.MenuSet
Dim visioMenusCol As Visio.Menus
Dim VisioMenu As Visio.Menu
Dim menuItemsCol As Visio.MenuItems
Dim mitem As Visio.MenuItem


menuUIObject = vApp.BuiltInMenus.MenuSets
menuMenuSets = menuUIObject '.MenuSets
menuMenuSet = menuMenuSets.ItemAtID(1010)
visioMenusCol = menuMenuSet.Menus 'menus collection. File ,Edit etc.
VisioMenu = visioMenusCol.Item(0) 'Represents a single menu on a
Microsoft Visio menu bar, such as the File menu or Edit menu.
menuItemsCol = VisioMenu.MenuItems 'Contains a MenuItem object for
each command on a Microsoft Visio menu.
mitem = menuItemsCol.Item(0) 'getting one item from File menu [New]
mitem.Enabled = False


Paul Herber

unread,
Dec 12, 2008, 6:57:21 PM12/12/08
to
Just follow the examples in the SDK and on John Marshall's website
http://visio.mvps.org/VBA.htm

> menuUIObject = vApp.BuiltInMenus.MenuSets

except, always check customs menus first. Also check for a nil object,
that means that the menu isn't available yet, do a processMessages
call and try again. (This usually means that Visio is displaying a
modal dialog box.)

> menuMenuSet = menuMenuSets.ItemAtID(1010)

Where did you get '1010' from? The menu IDs are defined in the SDK.


--
Regards, Paul Herber, Sandrila Ltd.
Electrical for Visio http://www.electrical.sandrila.co.uk/

Biggaford

unread,
Dec 15, 2008, 8:10:01 AM12/15/08
to

"Paul Herber" wrote:

Thank you very much for the tip. I added my own Menu along with a menu item
as in the code below; but one thing, i want the menu item to execute a
sub/function when it is click. How do i know when it is clicked, im not
seeing anything for that as yet. i want the visio doc to be saved with all
changes when the user print the doc. i disabled the original print menuitm
from the file menu, to allow my added menu item Reprint Visio to save the
file before printing so next time the doc is opened it has the saved changes.

The code:

Dim uiObj As Visio.UIObject
Dim visMenuSets As Visio.MenuSets
Dim visMenuSet As Visio.MenuSet
Dim visMenus As Visio.Menus
Dim visMenu As Visio.Menu
Dim visMenuItems As Visio.MenuItems
'Dim visMenuItem As Visio.MenuItem

Dim myMenu As Visio.Menu
Dim myMenuItem As Visio.MenuItem


'Check whether there are document custom menus.
If vDoc.CustomMenus Is Nothing Then

'If not, check whether there are application custom menus.
If vApp.CustomMenus Is Nothing Then

'If there are no custom menus, use the built-in toolbars.
uiObj = vApp.BuiltInMenus

Else

'If there are application custom menus, copy them.
uiObj = vApp.CustomMenus.Clone

End If

Else

'If there already are document custom menus, use them.
uiObj = vDoc.CustomMenus

End If

'uiObj = vApp.BuiltInMenus
visMenuSets = uiObj.MenuSets
' Get the Visio object context menu set.
visMenuSet = visMenuSets.ItemAtID(visUIObjSetDrawing)

'Get the Menus collection
visMenus = visMenuSet.Menus

' Get the file menu from the menus collection.
visMenu = visMenus.Item(0)

' Get the items collection from the file menu
visMenuItems = visMenu.MenuItems
visMenuItems(11).Enabled = False 'disabling print preview menu item.
visMenuItems(12).Enabled = False 'disabling print menu item.

myMenu = visMenus.AddAt(9)
myMenu.Caption = "DWReprint"
myMenuItem = myMenu.MenuItems.AddAt(0)
myMenuItem.State = Visio.VisUIButtonState.visButtonUp
myMenuItem.Caption = "Reprint Visio"

myMenuItem.CmdNum = visCmdFileSave
myMenuItem.CmdNum = visCmdFilePrint


' Set the new menus.
vApp.SetCustomMenus(uiObj)
' Tell Visio to use the new UI when the document is active.
vDoc.SetCustomMenus(uiObj)

Paul Herber

unread,
Dec 15, 2008, 7:29:55 PM12/15/08
to
On Mon, 15 Dec 2008 05:10:01 -0800, Biggaford
<Bigg...@discussions.microsoft.com> wrote:

>
>
>"Paul Herber" wrote:
>
>> Just follow the examples in the SDK and on John Marshall's website
>> http://visio.mvps.org/VBA.htm
>>
>> > menuUIObject = vApp.BuiltInMenus.MenuSets
>>
>> except, always check customs menus first. Also check for a nil object,
>> that means that the menu isn't available yet, do a processMessages
>> call and try again. (This usually means that Visio is displaying a
>> modal dialog box.)
>>
>> > menuMenuSet = menuMenuSets.ItemAtID(1010)
>>
>> Where did you get '1010' from? The menu IDs are defined in the SDK.
>>
>>
>

myMenuItem.AddOnName = // the name of the procedure
myMenuItem.AddonArgs = // procedure arguments

all as per the SDK.


--

Regards, Paul Herber, Sandrila Ltd.

Electronics for Visio http://www.electronics.sandrila.co.uk/

0 new messages