Yachrishere
New Member
- Joined
- May 6, 2019
- Messages
- 6
Hi. I am having a problem with a macro looking for a file with a variable name.
This is the code.
[vba]
Dim MyFile As String
Dim strFilePath As String
strFilePath = Range("E11").Value & "Quoting Files"
MyFile = Dir("Foundation*")
On Error GoTo Error_handler:
' all good so far
If CheckFileIsOpen("Foundations*") = True Then ' if there is a file open then it does what it should
MsgBox "File was already Open"
Workbooks("Foundations*").Activate
Application.GoTo Range("A1"), True
ActiveWindow.Zoom = 84
ActiveWindow.WindowState = xlMaximized
Else
Workbooks.Open Filename:=(sPath & "\Quote" & "\Quote Sheets" & MyFile) ' this is working as "sPath" is defined earlier
Application.GoTo Range("A1"), True
ActiveWindow.Zoom = 84
ActiveWindow.WindowState = xlMaximized
Exit Sub
Error_handler:
' now this is the problem part that gives me a runtime error 1004
Workbooks.Open Filename:=strFilePath & MyFile
Application.GoTo Range("A1"), True
ActiveWindow.Zoom = 84
ActiveWindow.WindowState = xlMaximized
MsgBox ("This is a Template File as the file does'nt appear in the folder" _
& vbNewLine & "You will need to save this to the Clients Folder")
End If
Unload UForm1
[vba]
the problem is with this line - Workbooks.Open Filename:=strFilePath & MyFile -
a runtime error 1004 says it can't find the folder but it does exist.
Any advice???
This is the code.
[vba]
Dim MyFile As String
Dim strFilePath As String
strFilePath = Range("E11").Value & "Quoting Files"
MyFile = Dir("Foundation*")
On Error GoTo Error_handler:
' all good so far
If CheckFileIsOpen("Foundations*") = True Then ' if there is a file open then it does what it should
MsgBox "File was already Open"
Workbooks("Foundations*").Activate
Application.GoTo Range("A1"), True
ActiveWindow.Zoom = 84
ActiveWindow.WindowState = xlMaximized
Else
Workbooks.Open Filename:=(sPath & "\Quote" & "\Quote Sheets" & MyFile) ' this is working as "sPath" is defined earlier
Application.GoTo Range("A1"), True
ActiveWindow.Zoom = 84
ActiveWindow.WindowState = xlMaximized
Exit Sub
Error_handler:
' now this is the problem part that gives me a runtime error 1004
Workbooks.Open Filename:=strFilePath & MyFile
Application.GoTo Range("A1"), True
ActiveWindow.Zoom = 84
ActiveWindow.WindowState = xlMaximized
MsgBox ("This is a Template File as the file does'nt appear in the folder" _
& vbNewLine & "You will need to save this to the Clients Folder")
End If
Unload UForm1
[vba]
the problem is with this line - Workbooks.Open Filename:=strFilePath & MyFile -
a runtime error 1004 says it can't find the folder but it does exist.
Any advice???