VBA - Using a macro to open a workbook

Joe94

New Member
Joined
Nov 19, 2010
Messages
20
Hi, at the moment I am trying to use a button to go to a sheet on a different workbook. I can do this fine if the workbook is already open, however if this workbook is closed an error message will pop up. I'm assuming there is a code to open up an excel file from a macro, which would hopefully solve my problem. Is there a code to open a different workbook from this macro and if so, what is it?
(Hopefully you can understand what i'm talking about)
Thanks in advance
Joe
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi there,

What error message do you get?

Make sure you have specified the directory:

Code:
Workbooks.Open Filename:= "H:\folder1\folder2\folder3\spreadsheet.xls"
 
Upvote 0
Hi Joe

Code:
Dim wb As Workbook
 
Set wb = Workbooks.Open("C:\SomeFolder\SomeFile.xls",UpdateLinks:=False)
 
wb.Sheets("Sheet1").Activate
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,286
Members
449,218
Latest member
Excel Master

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