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
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