Link to home
Start Free TrialLog in
Avatar of brothertruffle880
brothertruffle880Flag for United States of America

asked on

Visio VBA - Assigning 4 macros to 4 buttons throughout a visio file

I would like to have four macro buttons on every page of my 23 page visio file.

CommandButton1_click()
CommandButton2_click()
CommandButton3_click()
CommandButton4_click()

I attached code to each command button click event and they all work on one page but when I copy those same four buttons to another page.  I get command button5, 6, 7, 8.
When I try to rename the newly pasted button from command button5 back to commandbutton 1, I get "Ambiguous Name Detected Command Button 1"
I don't want to reprogram or copy code over and over again.
I want to invoke those same four code modules regardless of what page they're on.
Avatar of COACHMAN99
COACHMAN99

does it matter what the button is called? surely you will call the same code/function regardless?
e.g.
CommandButton1_click()
   functionA()

CommandButton2_click()
   functionA()

CommandButtonNN_click()
   functionA()
Avatar of brothertruffle880

ASKER

Doesn't matter what the buttons are called but I'm trying to avoid typing code over and over.
or pasting code over and over I have 28 pages.  multiply that by four buttons 28 x 4 = 112 event procedures!

Here is the code I want to attach to each button:
 
Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  Call m_showAndHideLayers(pg, LayerName_Mgmt$)
  Set pg = Nothing

Open in new window


Of course MGMT$ will change because each button will invoke a different layer.
Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  Call m_showAndHideLayers(pg, LayerName_Wireless$)
  Set pg = Nothing

Open in new window

etc.
got it. didn't know you were referencing the current page in your code.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi CodeCruiser
This is a useful solution and I will use it But my problem is different.
I have awarded you the points because it's a terrific piece of code.