Hi
Ive got a VBA code that opens a file where the user chooses a file
and another code to open another workbook on a set path
Now it gives an Error 1004 stating that the file is not there. If the user selects a file in the same folder as the set path the code works fine. It only errors if the user selects a different path for the 1st code.
The error highlights this code
Ive got a VBA code that opens a file where the user chooses a file
VBA Code:
Dim fileNameAndPath As Variant
fileNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
If fileNameAndPath = False Then Exit Sub
'Workbooks.Open Filename:=fileNameAndPath
Set wbCopy = Workbooks.Open(fileName:=fileNameAndPath, ReadOnly:=True)
Set wsCopy = wbCopy.Worksheets(1)
and another code to open another workbook on a set path
VBA Code:
Dim ACpath As String
Dim ACname As String
Dim fullACname As String
Dim fExt As String
ACpath = "\\foldername\different folder\Macro\"
ACname = "Availability Codes"
fExt = "xlsx"
fullACname = Dir(ACpath & ACname & "*.*.*." & fExt)
Set wbAvailabilityCodes = Workbooks.Open(fullACname)
Set wsAvailabilityCodes = wbAvailabilityCodes.Worksheets(1)
Now it gives an Error 1004 stating that the file is not there. If the user selects a file in the same folder as the set path the code works fine. It only errors if the user selects a different path for the 1st code.
The error highlights this code
VBA Code:
Set wbAvailabilityCodes = Workbooks.Open(fullACname)