sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,418
- Office Version
- 2016
- Platform
- Windows
Hi guys - I'm encountering an error when I try to save a template as a .xlsx file.
The error is object variable or with block variable not set and it appears on line 40 of this code:
The save routine is here:
The file saves fine, as expected, but I get that error afterwards and I don't understand why - can anyone clear up my confusion?
The error is object variable or with block variable not set and it appears on line 40 of this code:
VBA Code:
Private Sub Workbook_Open()
10 If Sheets("SUMMARY").Range("D2").Value = "" Then
20 AnswerYes = MsgBox("Import Data?", vbQuestion + vbYesNo, "Import")
30 If AnswerYes = vbYes Then
40 ImportFrm.Show
50 End If
60 End If
End Sub
The save routine is here:
VBA Code:
Sub SaveFile()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
If InStr(Sheets("SUMMARY").Range("D2").Value, "2023") Then ImportYear = "2023"
If InStr(Sheets("SUMMARY").Range("D2").Value, "2024") Then ImportYear = "2024"
Filename = Sheets("SUMMARY").Range("D2").Value & " Times Data"
FilePath = Drive & "Times\Completed\" & ImportYear
ThisWorkbook.SaveAs Filename:=FilePath & "\" & Filename & ".xlsx", FileFormat:=51
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The file saves fine, as expected, but I get that error afterwards and I don't understand why - can anyone clear up my confusion?