Matt5353

Board Regular
Joined
Nov 30, 2018
Messages
60
Office Version
  1. 2016
Platform
  1. Windows
I have a user form with twelve command buttons on 8, 12, 14, 16 etc up to 30.
Now I have 12 workbooks I wish to attach to each Command Button.
Try as I might I cannot attach the workbook to the command button.
If I can get one to connect when pressed then I can just copy the code for all the others
Andrew
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
.
If you mean open another worbook :

Code:
Option Explicit


Sub openWB()
Dim wkbk As Workbook
On Error Resume Next
On Error GoTo 0


    If wkbk Is Nothing Then
        Set wkbk = Workbooks.Open(Environ("UserProfile") & "\Desktop\Spiral 3.xlsm")
    End If


wkbk.Activate
End Sub
 
Upvote 0
I have a user form with twelve command buttons on 8, 12, 14, 16 etc up to 30.
Now I have 12 workbooks I wish to attach to each Command Button.
Try as I might I cannot attach the workbook to the command button.
If I can get one to connect when pressed then I can just copy the code for all the others
Andrew

Hi,
Use the code for the each command buttoch changing only the value of the parameter FileName writing full directory of the workbook you want to open.
Code:
Workbooks.open FileName:="C:\data\MyWorkbook.xlsx"
[\CODE]
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,843
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top