Hi
I am looking for code to save a copy of the current xlsm workbook in xls format with the same name and directory (and/or create it with no Dialog box) and continue working on the xlsm file. The xls file does not need to open.
Here is why: I am sorting addresses on more that 3 levels (2007 feature) but the mapping program only reads non macro enabled formatted workbooks.
Hence both files need to remain in sync but only the xlsm file is used to work on the data. If the "save" operation is not initiated manually with a Macro button, at the latest, upon closing of the xlsm file, a "Save" of the xls should be triggered without affecting the normal save and close of the current xlsm file. Also, the xls version of current file should take place without the dialog message regarding the loss of functionality in xls, xlsx, etc, files... popping up).
I included the following code in the Before_Close phase of the workbook (not sure if that is the right way to do it) and also created a button on a worksheet to occasionally trigger the an update (Save) of the xls file but I don't know enough about VBA.
This code seems to work but it asks for the name of a file (even though it is already there and should be used), warns about overwriting it (even though that is what needs to happen), and then the xlsm closes and the new file becomes active workbook (not the desired one).
Please help. Thanks
Here is the code I came up with so far after many hours of frustration:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim fileSaveName As String
Dim sourcewb As String
Dim tempfilename As String
Application.EnableEvents = False
Do
fileSaveName = Application.GetSaveAsFilename(fileFilter:="Excel 2003 Files (*.xls), *.xls")
If fileSaveName <> "False" And Right(fileSaveName, 4) <> ".xls" Then
MsgBox ("FILE NOT SAVED - please save in .xls format")
End If
Loop Until fileSaveName = "False" Or Right(fileSaveName, 4) = ".xls"
If fileSaveName <> "False" Then
ThisWorkbook.SaveAs Filename:=fileSaveName
End If
Cancel = True
Application.EnableEvents = True
End Sub
I am looking for code to save a copy of the current xlsm workbook in xls format with the same name and directory (and/or create it with no Dialog box) and continue working on the xlsm file. The xls file does not need to open.
Here is why: I am sorting addresses on more that 3 levels (2007 feature) but the mapping program only reads non macro enabled formatted workbooks.
Hence both files need to remain in sync but only the xlsm file is used to work on the data. If the "save" operation is not initiated manually with a Macro button, at the latest, upon closing of the xlsm file, a "Save" of the xls should be triggered without affecting the normal save and close of the current xlsm file. Also, the xls version of current file should take place without the dialog message regarding the loss of functionality in xls, xlsx, etc, files... popping up).
I included the following code in the Before_Close phase of the workbook (not sure if that is the right way to do it) and also created a button on a worksheet to occasionally trigger the an update (Save) of the xls file but I don't know enough about VBA.
This code seems to work but it asks for the name of a file (even though it is already there and should be used), warns about overwriting it (even though that is what needs to happen), and then the xlsm closes and the new file becomes active workbook (not the desired one).
Please help. Thanks
Here is the code I came up with so far after many hours of frustration:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim fileSaveName As String
Dim sourcewb As String
Dim tempfilename As String
Application.EnableEvents = False
Do
fileSaveName = Application.GetSaveAsFilename(fileFilter:="Excel 2003 Files (*.xls), *.xls")
If fileSaveName <> "False" And Right(fileSaveName, 4) <> ".xls" Then
MsgBox ("FILE NOT SAVED - please save in .xls format")
End If
Loop Until fileSaveName = "False" Or Right(fileSaveName, 4) = ".xls"
If fileSaveName <> "False" Then
ThisWorkbook.SaveAs Filename:=fileSaveName
End If
Cancel = True
Application.EnableEvents = True
End Sub