Hello,
I cannot figure this out for the life of me....
I'm creating a macro to open a file, format it, print it, and close it. Everything goes will until the closing part. See code below. When it gets to the line to close the file it bugs out. I would appreciate any assistance.
I cannot figure this out for the life of me....
I'm creating a macro to open a file, format it, print it, and close it. Everything goes will until the closing part. See code below. When it gets to the line to close the file it bugs out. I would appreciate any assistance.
Code:
Sub run_macro()
Dim sfile As String
Dim tfile As Variant
Dim vFile As Variant
sfile = Dir("C:\temp\reports\Report " & Format((Date - 1), "mm dd yyyy") & ".xls")
tfile = "Report " & Format((Date - 1), "mm dd yyyy") & ".xls"
If sfile <> "" Then
Workbooks.Open Filename:="C:\temp\reports\Report " & Format((Date - 1), "mm dd yyyy") & ".xls"
Else:
vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
"*.xl*", 1, "Where is " & tfile & "?", "Open", False)
If vFile = False Then
MsgBox (tfile & " not printed")
Exit Sub
End If
Workbooks(vFile).Open
End If
[simple formating code here]
Workbooks(vFile).Close SaveChanges:=False
End Sub