Dear Fellow MS Excel Macro Support Team,
I added 3 developer- modules to my macro-excel file and after I quit the application and start the file again I get an error message saying that my file is bad and cannot be fixed or repaired, or viewed. The error message that I get is:
"Excel cannot open the file 'Invoice Template.xlsm' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
And the 3 modules that I have or three macros, are:
Option Explicit
Sub SaveInvAsExcel()
Dim invno As Long
Dim custname As String
Dim amt As Currency
Dim dt_issue As Date
Dim term As Byte
Dim path As String
Dim fname As String
invno = Range("C3")
custname = Range("B10")
amt = Range("H41")
dt_issue = Range("C4")
term = Range("C6")
path = "/Users/pettygoose/Library/Mobile Documents/com~apple~CloudDocs/Company Files/Sales/EXCEL"
fname = "Inv No.#" & invno & ".xlsx"
Sheet1.Copy
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
shp.Delete
Next shp
With ActiveWorkbook
.Sheets(1).Name = "Invoice"
.SaveAs FileName:=path & fname, FileFormat:=51
.Close
End With
End Sub
Sub CreateNewInvoice()
Dim invno As Long
invno = Range("C3")
Range("C4").MergeArea.ClearContents
Range("B10").MergeArea.ClearContents
Range("B19").MergeArea.ClearContents
Range("B20").MergeArea.ClearContents
Range("B21").MergeArea.ClearContents
Range("B22").MergeArea.ClearContents
Range("B23").MergeArea.ClearContents
Range("B24").MergeArea.ClearContents
Range("B25").MergeArea.ClearContents
Range("B26").MergeArea.ClearContents
Range("G19, F19").ClearContents
Range("G20, F20").ClearContents
Range("G21,F21").ClearContents
Range("G22,F22").ClearContents
Range("G23,F23").ClearContents
Range("G24,F24").ClearContents
Range("G25,F25").ClearContents
Range("G26,F26").ClearContents
Range("G27,F27").ClearContents
MsgBox "Your next invoice number is " & invno + 1
Range("C3") = invno + 1
Range("B10").Select
ThisWorkbook.Save
End Sub
Sub RecordofInvoice()
Dim invno As Long
Dim custname As String
Dim amt As Currency
Dim dt_issue As Date
Dim term As Byte
Dim nextrec As Range
invno = Range("C3")
custname = Range("B10")
amt = Range("H41")
dt_issue = Range("C4")
term = Range("C6")
Set nextrec = Sheet3.Range("A1048576").End(xlUp).Offset(1, 0)
nextrec = invno
nextrec.Offset(0, 1) = custname
nextrec.Offset(0, 2) = amt
nextrec.Offset(0, 3) = dt_issue
End Sub
What went wrong? Why is it breaking the macro-excel file?