Application.ThisWorkbook.Path not working with CreateObject("Scripting.FileSystemObject").FileExists

shlobodon

New Member
Joined
Oct 15, 2015
Messages
44
Hi Excelors!

I have the following code. If CreateObject("Scripting.FileSystemObject").FileExists(thesentence) Then has a result of FAILED. However, when it runs the line Workbooks.Open Filename:=currentdirectory & "\Rebate Report Output\" & strfile, the workbook opens. Obviously the file exists if it is being opened using the SAME PATH

Any advice?

Option Compare Text
Sub test8()
Dim currentdirectory As String
Dim strfile As String
Dim thesentence As String

customername = "BMS"
currentdirectory = Application.ThisWorkbook.Path
DateRange = "Oct'22 - Sep'23"
strfile = customername & "_Rebate Report_" & DateRange & ".xlsx"

thesentence = currentdirectory & "\Rebate Report Output\" & strfile

If CreateObject("Scripting.FileSystemObject").FileExists(thesentence) Then
MsgBox "worked"
Else
MsgBox "failed"
End If
Workbooks.Open Filename:=currentdirectory & "\Rebate Report Output\" & strfile

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Technically I don't see anything wrong with your code - I copied it and used it both locally and on a network.
But - where is your workbook stored? I have had a huge problem lately with using "Thisworkbook.path" because unbeknownst to users, their desktop (for example) is in the cloud, so thisworkbook.path returns an https. Course, I'm not sure why your .Open would work - but then I haven't tried that specific command.
 
Upvote 0
Solution
Technically I don't see anything wrong with your code - I copied it and used it both locally and on a network.
But - where is your workbook stored? I have had a huge problem lately with using "Thisworkbook.path" because unbeknownst to users, their desktop (for example) is in the cloud, so thisworkbook.path returns an https. Course, I'm not sure why your .Open would work - but then I haven't tried that specific command.
Thank you Starl! Yes, it is being pulled from a cloud. Thank you for your insight! I will have to find a way around it 😅
 
Upvote 0
Thank you Starl! Yes, it is being pulled from a cloud. Thank you for your insight! I will have to find a way around it 😅
I think I will open the workbook since it does open, then test to see if it's open. Hopefully this would suit my needs
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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