Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:11:06+00:00 2026-06-16T16:11:06+00:00

I have an Excel template file . Based on the Excel version, I would

  • 0

I have an Excel template file . Based on the Excel version, I would like to SaveAs as Temp.xlsm through Matlab.

Here is the code I am using to save the template file :

if(XLversion >= 12.0)
    Workbook = invoke(Excel.Workbooks,'Open',tempxls);
    tempxls1 = [pwd '\utils\temp.xlsm'];
    Workbook.SaveAs(tempxls1,1);
    tempxls = tempxls1;
    extn = 'xlsm';
end

The code is working fine. However when I try to open the file, I get the following error :

enter image description here

However, when the save the temp.xls to temp.xlsm through SaveAs menu, it opens without any error.

Any idea what could be the error in the code or If I am missing something.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:11:07+00:00Added an answer on June 16, 2026 at 4:11 pm

    Can you try the following code please and comment. You may call this sub-routine to save the as the file.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim FileNameVal As String
    If SaveAsUI Then
        FileNameVal = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")
        Cancel = True
        If FileNameVal = "False" Then 'User pressed cancel
            Exit Sub
        End If
        Application.EnableEvents = False
            If Right(ThisWorkbook.Name, 5) <> ".xlsm" Then
                ThisWorkbook.SaveAs Filename:=FileNameVal & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
            Else
                ThisWorkbook.SaveAs Filename:=FileNameVal, FileFormat:=xlOpenXMLWorkbookMacroEnabled
            End If
        Application.EnableEvents = True
    End If
    End Sub
    

    Reference:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to open Excel template file and save it as
I have a template excel file to generate excel files from it. My code
I have built template-based add ins for Word and Excel version 2003 and previous.
I have an excel file (that I use as a template) with two rows.
I have an excel template that uses a macro to save the file, so
I need help in this matter: We have a template of Excel file in
I currently have an excel file (.htm) that I use as a template for
Ok I have a excel template file which contains various headers, images etc. I
My program have ability to export some data and DataTable to Excel file (template)
Good Afternoon, I have a an Excel template file - which contains Macros -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.