Share via

[Macro Coding - MS Excel ]After adding Modules to Microsoft Excel I cannot Open my .xlsm - Using Macros

Anonymous
2023-09-05T07:39:13+00:00

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?

Microsoft 365 and Office | Excel | For home | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-09-06T00:13:10+00:00

    We await your response so we can help further and also help provide better feedback on what you have tried in the suggestions and what you see now, which will help the whole forum.

    Adeyemi

    Was this answer helpful?

    0 comments No comments
  2. Jim G 134K Reputation points MVP Volunteer Moderator
    2023-09-05T20:04:05+00:00

    Hi

    The presence or absence of the macro should make no difference.

    Please let us know what version of Excel you have. Use the Menu Bar and choose Excel > About Microsoft Excel to display that information.

    File saving and opening is handled by Mac OS. I don't see anything in the code or file name that would result in file corruption. My advice is to repair the file system as a first step. Then try saving again and let us know the results. How to repair a Mac disk with Disk Utility - Apple Support

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-09-05T09:19:58+00:00

    Hello

    I’m Adeyemi and I’d be happy to help you with your question.

    The error message you're receiving suggests that the file format or file extension is not valid, or that the file has been corrupted.

    It's difficult to determine the exact cause of the issue without more information, but here are some possible reasons why this might be happening:

    • The file may have become corrupted during the process of adding the modules or while saving and closing the file.
    • There may be an issue with the macros or modules that were added to the file, causing it to become unreadable by Excel.
    • There may be a compatibility issue between the version of Excel you're using and the file format of the .xlsm file.

    Here are some steps you can try to recover your data and fix the issue:

    1. Try opening the file in a different version of Excel or on a different computer to see if the issue persists.
    2. If you have a backup copy of the file, try opening it to see if it works correctly.
    3. If you don't have a backup copy, try using the Open and Repair feature in Excel to repair the file. To do this, open Excel, click on File > Open, then navigate to the location of your .xlsm file. Instead of double-clicking on the file to open it, click on the drop-down arrow next to the Open button and select Open and Repair.
    4. If none of these steps work, you might want to consider using a third-party data recovery tool to recover your data from the corrupted file.

    I hope these suggestions help!

    Give back to the Community. Help the next person who has this issue by indicating if this reply solved your problem. Click Yes or No below

    Regards Adeyemi

    Was this answer helpful?

    0 comments No comments