Solved

Excel VBA save a xlsm file as xlsx

Posted on 2012-03-15
5
9,665 Views
Last Modified: 2012-03-15
I have an xlsm file with a large macro in it. The macro processes the file, and prepares it for sending out via email. I'd like the last step of the macro to save the file as an xlsx, with a name specified via VBA.

When the macro gets up to this line of code:
    ActiveWorkbook.SaveAs "C:\test.xlsm", FileFormat:=51

I get an error:
This extension cannot be used with the selected file type. Change the file extension in the File name text box or select a different file type by changing the Save as Type.

Can anyone help me?
0
Comment
Question by:etech0
  • 2
  • 2
5 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 37724992
Why aren't you using .xlsx?
0
 
LVL 13

Expert Comment

by:Shanan212
ID: 37725002
    ActiveWorkbook.SaveAs Filename:= _
        "C:\test.xlsx",  FileFormat:=xlOpenXMLWorkbook, ReadOnlyRecommended:=False, CreateBackup:=False

Open in new window


try this
0
 
LVL 10

Author Comment

by:etech0
ID: 37725052
Thanks!!!!
Now how do I get rid of this one:?

The following features cannot be saved in a macro free workbook: VB Project....

I know - that's the whole point. Can I tell it not to warn me?
0
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 total points
ID: 37725075
Put this before the save
Application.DisplayAlerts = false


and this after
Application.DisplayAlerts = True

Application.DisplayAlerts = false
Application.EnableEvents = False
    ActiveWorkbook.SaveAs Filename:= _
        "C:\test.xlsx",  FileFormat:=xlOpenXMLWorkbook, ReadOnlyRecommended:=False, CreateBackup:=False
Application.EnableEvents = True
Application.DisplayAlerts = True

Open in new window

0
 
LVL 10

Author Closing Comment

by:etech0
ID: 37725413
Thanks! That's a big help...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question