Set Workbook from Path

cha

New Member
Joined
Aug 16, 2011
Messages
21
Hi,

In order for me to access workbooks, I have to first have them saved in the same directory as the book I'm currently working in, then I have to make a call to open them. Then later, I close them. I know there has to be an easier way.

Code:
 Workbooks.Open ("W:\Everyone\Reference.xls")
    Set GlobalCourses_file = Workbooks("W:\Everyone\Reference.xls")
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
In order for me to access workbooks, I have to first have them saved in the same directory as the book I'm currently working in, then I have to make a call to open them.
What leads you to believe that?

Code:
    Dim wkb As Workbook
    
    Set wkb = Workbooks.Open("W:\anypath\anyfile.xls")
 
Upvote 0
Unless you dont have permission to access the directory you should be able to open it from different folders E.G.

Code:
Workbooks.Open Filename:="C:\some folder\some workbook.xls"

i use this with a variable to open a workbook in one of my macros:

Code:
On Error GoTo errOpenStatusSheet
            Workbooks.Open Filename:=strStatusSheetLocation & strStatusSheetFilename, UpdateLinks:=2, ReadOnly:=True
            On Error GoTo ErrorHandler
 
Upvote 0
Let me be more clear...
What I really mean to ask is do the workbooks need to be open for me to set them as objects?

Why can't I do this:

Code:
set wkb = Workbooks("W:\something.xls")
 
Upvote 0
From Help:

The Workbook object is a member of the Workbooks collection. The Workbooks collection contains all the Workbook objects currently open in Microsoft Excel.
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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