Link to home
Start Free TrialLog in
Avatar of Bright01
Bright01Flag for United States of America

asked on

Integrating two macros into one

I have a great little form/macro that byandt wrote for me that keeps an option to edit and return visible in a spreadsheet.  The challenge I have is I have two macros that need to be placed into the form/macro and I don't know how to incorporate them into what was sent.

Thanks in advance,

B.
Moving-Buttons-with-the-cellsQ28721.xlsm
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

Where do you want the two macros to run?  There's no code in the UserForm except two test messages.
As Roy implied it's hard to tell what macro's you want to run. One thing I can say is that if one is called Macro1 and the other is called Macro2 then a 3rd macro can be written like this that will run them both.

Sub Macro3()

' Run Macro1
Macro1

'Run Macro2
Macro2
End Sub

Open in new window

Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try ( inthe form module)

Option Explicit

Private Sub CommandButton1_Click()
'Private Sub CommandButton2_Click()

'If CommandButton1.Caption = "Display More" Then
If CommandButton1.Caption = "Display Questions" Then
    'Your two macros look the same to me except for the name, but
    'reguardless you would put the name of the one that you want to
    'run when the caption says "Expand" here
    Contract_All '
'    Else
    'Expand_All
Else
If CommandButton1.Caption = "Display Details" Then
    'Your two macros look the same to me except for the name, but
    'reguardless you would put the name of the one that you want to
    'run when the caption says "Expand" here
    Expand_All
Else
If CommandButton1.Caption = "Display More Detail" Then
    'Your two macros look the same to me except for the name, but
    'reguardless you would put the name of the one that you want to
    'run when the caption says "Expand" here
    Details_All
End If
End If
End If

End Sub


Private Sub CommandButton2_Click()
Run 'G:\PC Dev Data\PCI Workbench\PCI Workbench v113.xlsm'!Sheet34.ReturntoDirections_Click
End Sub
Sub Contract_All()
'ActiveSheet.Unprotect Password:="jam"
ActiveSheet.Outline.ShowLevels Rowlevels:=1
'ActiveSheet.Protect Password:="jam"
ActiveSheet.EnableSelection = xlUnlockedCells
CommandButton1.Caption = "Display Details"
Range("A3").Activate
End Sub

Sub Expand_All()
'ActiveSheet.Unprotect Password:="jam"
ActiveSheet.Outline.ShowLevels Rowlevels:=2
'ActiveSheet.Protect Password:="jam"
ActiveSheet.EnableSelection = xlUnlockedCells
CommandButton1.Caption = "Display More Detail"
Range("A3").Activate
End Sub
Sub Details_All()
'ActiveSheet.Unprotect Password:="jam"
ActiveSheet.Outline.ShowLevels Rowlevels:=3
'ActiveSheet.Protect Password:="jam"
ActiveSheet.EnableSelection = xlUnlockedCells
CommandButton1.Caption = "Display Questions"
Range("A3").Activate
End Sub

Sub ReturntoDirections_Click()
'This brings up the Directions for review
Sheet34.Visible = xlSheetHidden
Sheet25.Visible = xlSheetVisible
Sheet25.Activate
End Sub

Open in new window

Regards
SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India 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
ASKER CERTIFIED SOLUTION
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
Avatar of Bright01

ASKER

Great Teamwork to all!  This was a horrible "ask" with little detail.  And sorry for being "off the grid" for several days.  In the end, it worked....... required a little trouble shooting to incorporate it but you guys did great and helped me learn more about how to use Forms!

Much thanks,

B.