VBA - Using a macro to open a workbook

Joe94

New Member
Joined
Nov 19, 2010
Messages
18
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
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,216
Messages
5,594,885
Members
413,947
Latest member
gizmolucy

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