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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
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"
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Joe

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

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,157
Messages
5,835,713
Members
430,381
Latest member
tntcute

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
Top