Save a *.xlsm file as *.xlsx and suppress the pop-up - vba

The current active workbook is a macro-enabled one.
After performing some automated data manipulation, I want to save it as a new macro-free workbook (thus .xlsx instead of .xlsm). To do this, I recorded and edited a macro:
Dim newFilePath As string
newFileFullName = "C:\List.xlsx"
ActiveWorkbook.SaveAs Filename:=newFileFullName, FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False
Workbooks.Open Filename:=newFileFullName
Windows("List.xlsx").Activate
However, whenever I run this macro, a window keeps popping up, asking for confirmation that I want to change the file format.
How can I suppress this pop-up and default it to "Yes"?

Add Application.DisplayAlerts = False
Thanks #simoco

Related

VBA Overwrite Addin Workbook

So I have done some research but I can't get the feature I am looking for to work.
I am deploying a workbook to a lot of people on a network. I have an add-in on a network drive that all of the workbooks reference to. It works great when running the macros, no problem at all. My issue is updating the macros when people have one of the workbooks open. People leave things open for days sometimes, I know, cause I do the same thing sometimes.
I found this link, with the code below but I can't get it to work.
https://www.excelguru.ca/content.php?152-Deploying-Add-ins-in-a-Network-Environment
The macro saves it as a .xlsm or a macro enabled workbook. It won't save it as a .xla
Sub DeployAddIn()
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: To deploy finished/updated add-in to a network
' location as a read only file
Dim strAddinDevelopmentPath As String
Dim strAddinPublicPath As String
'Set development and public paths
strAddinDevelopmentPath = ThisWorkbook.Path & Application.PathSeparator
strAddinPublicPath = "F:\Addins" & Application.PathSeparator
'Turn off alert regarding overwriting existing files
Application.DisplayAlerts = False
'Save the add-in
With ThisWorkbook
'Save to ensure work is okay in case of a crash
.Save
'Save read only copy to the network (remove read only property
'save the file and reapply the read only status)
On Error Resume Next
SetAttr strAddinPublicPath & .Name, vbNormal
On Error Goto 0
.SaveCopyAs Filename:=strAddinPublicPath & .Name
SetAttr strAddinPublicPath & .Name, vbReadOnly
End With
'Resume alerts
Application.DisplayAlerts = True
End Sub
I've tried doing
.SaveAs FileFormat:=xlAddIn
Or
.`SaveAs FileFormat:=18`
Niether of those work. SaveCopyAs doesn't have a fileformat option.
Any suggestions or any other methods that might work?
You keep a copy of the XLAM on your local machine that you update, and then when you are ready to deploy it, you copy the XLAM to the server. Everyone else runs off a copy that is on the server (you dont want them to copy it to their local machine, btw) - The key is that when you copy it to the server, you have to set it to read-only in the file properties. You have to do that every time you copy it. Then you can overwrite it at any time.
Comment if you have any questions - I do this every day for work.

What am I missing in my code that doesn't "Close" the workbook (.xlsm) after saving it?

What is the proper code to input in the module/button that will specifically prompt the user to "SaveAs", "Close" the (.xlsm) file, and open the same "New" sheet again?
I want to create an excel micro-enabled file .xlsm that will have a button called, "Save&New". The module/button will SaveAs, close the current file and open the same file again. For instance, when I'm filling out an audit and using the .xlsm sheet, I want to click the "Save&New" button for it to SaveAs, close it, and open the same file again but not the one I saved. Look at it has a template; only that I want the button to SaveAs, close the file, and open a "new" fresh file automatically.
Here is what I have so far:
In this image you see that I created the button called, "Save&New".
[enter image description here][1]
When I click on the "Save&New", it will "SaveAs" the .xlsm sheet.
[enter image description here][2]
This is where I need help. After saving the sheet, I want the workbook to "Close" the file.
And open the same sheet before to work on a "New" audit workbook form (.xlsm). (Not the sheet that was saved, but the sheet open before modifying it)
This is the code that I have inside the module/button called, "Save&New":
Sub Button7_Click()
Application.Dialogs(xlDialogSaveAs).Show
Dim oWB As Excel.Workbook
For Each oWB In Application.Workbooks
If oWB.Name = "_temp.xls" Then
oWB.Close
Exit For
End If
Next
Set oWB = Nothing
Workbooks.Open ("Communications Subdivisions System Audit.xlsm")
ActiveWorkbooks.Close
End Sub
The code currently "SaveAs" and it opens a "New" sheet of the same one that was used before saving it. The problem is that it doesn't close the workbook that was saved before, although it does open the "New" sheet.
Specifically, my question is:
What am I missing in my code that doesn't "Close" the workbook (.xlsm) after saving it and still opens a "New" sheet again?
Unless there is more involved with the macro, you might be able to accomplish this entirely via a "Template" feature already built into Excel and save yourself a ton of work and trouble.
Get your "new" file the way you want it, choose "Save As", and then in the File Types section choose "Excel Template (*.xltx)". Note this will change the selected save folder, so put the save dialog back where you really want the file and save it.
Now, every time you open this file you get a new copy, and when you do a regular save it won't make changes to the original.
Seems that the _ is comparing as a wildcard not as a literal string.
I played around and for some reason using the wildcard escape key doesn't work unless you compare with Like instead of =
This should work:
Dim oWB As Excel.Workbook
For Each oWB In Application.Workbooks
If oWB.Name Like "[_]temp.xlsm" Then
oWB.Close
Exit For
End If
Next

Macro: Programmatically Remove Known Excel Passwords

Is there a means to remove a KNOWN password from an Excel file via a VBA macro? Web searches only return the method to crack unknown Excel passwords.
I've automated all other aspects of the data handling except downloading files from an FTP site and subsequently removing the password.
You'll need to open the workbook specifying the passwords to open and modify, then saveas specifying an empty password for open and modify. To avoid getting prompts when overwriting the existing file, you need to disable alerts.
e.g.
Sub OpenAndSaveWithoutPasswords()
Dim wb As Workbook
Application.DisplayAlerts = False
Set wb = Workbooks.Open(Filename:="YOUR PATH AND FILENAME", Password:="OPEN PASSWORD", WriteResPassword:="MODIFY PASSWORD")
wb.SaveAs Filename:="YOUR PATH AND FILENAME AGAIN", Password:="", WriteResPassword:=""
Application.DisplayAlerts = True
End Sub
Note: Workbooks.Open seems to require brackets, wb.SaveAs requires no brackets (don't ask me why).
Just resave the workbook without a password:
ActiveWorkbook.SaveAs

Copy workbook containing macro to a workbook without macro

I am able to duplicate a workbook (copy to a desired location) which contains a macro in the background. This duplicate copy also contains the same macro.
My Problem is I do not want this duplicate workbook to have a macro with it. Can anyone tell how to do it?
Thank you in advance!!!
Save your workbook as macro-free, i.e. simply as Excel Workbook. For my Excel 2007 this is done using:
Application.DisplayAlerts = False
ThisWorkbook.CheckCompatibility = False
ThisWorkbook.SaveAs Filename:="D:\DOCUMENTS\Book1.xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
Correct path & name as you wish.
Read more about SaveAs method: http://msdn.microsoft.com/en-us/library/office/ff841185%28v=office.14%29.aspx
...and available File Formats: http://msdn.microsoft.com/en-us/library/office/ff198017%28v=office.14%29.aspx
Hope that was helpful)

How to save a read-only file as a different file extension in an excel macro?

I have a macro setup to automatically open/save a file that I am opening from the web. The web format is a #csv.gz format. I have code that currently just saves the file in the default location (which I have changed to c:\files). I want to write a macro that will keep the filename of the file, but change the extention to just file.xlsm. Is there a way to do this with VBA/excel? The reason while I need to change the extension is because it currently does not work with my formulas. The default save code I have just saves the file as a #csv.txt.
Is this possible?
Integrate this code into your own:
Sub SaveIt()
Dim wkb As Workbook
Set wkb = ActiveWorkbook 'change to your workbook reference
wkb.SaveAs Replace(wkb.Name, ".txt", ""), 52 'change ".txt" to ".csv" if need be
End Sub
See Excel File Type Enum for more information the 52.