Cannot access workbook using full path of the file

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
When I use the following code everything works:

Code:
Dim wb As String
wb = "xlwings_temp2.xlsx"
Workbooks(wb).Activate
Application.ScreenUpdating = True
Workbooks(wb).Save

But I'm going to be moving files around and accessing this subroutine from other folders so I need to use the full path but I cannot get it to work. I already looked up the full path using the locals window. So when I put in:

Code:
Dim wb As String
wb = "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/proofs/other/xlwings_temp2.xlsx"
Workbooks(wb).Activate
Application.ScreenUpdating = True
Workbooks(wb).Save

That failed. I also tried:

Code:
Dim pt As String, cd As Workbook
pt = "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/proofs/other/xlwings_temp2.xlsx"
Workbooks.Open FileName:=pt
Set wb = Application.Workbooks(pt)
Application.ScreenUpdating = True
wb.Save
But that failed too. I'm getting a subscript out of range error whenever I use the long string. The following image will demonstrate that I'm using the correct string. I know mrexcel does not like linking to 3rd party sites but I have no way to posting a screenshot other than the following.

https://ibb.co/mHzaoz
mHzaoz
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try
Code:
Dim pt As String, Wb As Workbook
pt = "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/proofs/other/xlwings_temp2.xlsx"
Set Wb = Workbooks.Open(Filename:=pt)
 
Upvote 0
That path is not the full path, what you have there is known and UNC

Try hardcode (hardcode) the full path etc and see if that is better assumes you have rightful access (privileges to the network share)

or change the UNC to "\\........ not "\......



jiuk
 
Upvote 0
@jiuk
Those are MAC paths, not PC paths. ;)
 
Upvote 0
Hey Fluff

Don't worry I am going rather slightly crazy these days, too much work on so many different systems and hardware!
 
Upvote 0
Problem solved. It turns out that Excel does not need the full path of the file in order to activate it. As long as the file is open, it will activate that file no matter what file it is in. I'm guessing that it only needs the full path in order to open a file.
 
Upvote 0
I'm guessing that it only needs the full path in order to open a file.

That's correct. You can only have one file open with a given name, so the path would be unnecessary.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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