• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to save the file with macro code

ThrottleWorks

Excel Ninja
Hi,

I am trying to save as a file. Original file is a macro. When I save as the file and re-open it I cannot see code in the file.

I know I am doing some silly mistake here but not able to find.

Can anyone please help me in this.

Please note original file is in .xls format.

Code:
Sub Save_File()

Application.DisplayAlerts = False

Dim sFilename As String

Dim MappingSht As Worksheet

Dim MyFolderPath As String

Set MappingSht = MacroBook.Worksheets("Tab_Headers")

MyFolderPath = MappingSht.Range("B1").Value

sFilename = Worksheets("Summary").Range("A3").Value

ActiveWorkbook.SaveAs Filename:=MyFolderPath & sFilename & ".xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

Range("A1:A3").ClearContents

  ThisWorkbook.Worksheets("Summary").Range("A1:A3").ClearContents
Application.DisplayAlerts = True
End Sub
 
Hi,

I am trying to save as a file. Original file is a macro. When I save as the file and re-open it I cannot see code in the file.

I know I am doing some silly mistake here but not able to find.

Can anyone please help me in this.

Please note original file is in .xls format.

Code:
Sub Save_File()

Application.DisplayAlerts = False

Dim sFilename As String

Dim MappingSht As Worksheet

Dim MyFolderPath As String

Set MappingSht = MacroBook.Worksheets("Tab_Headers")

MyFolderPath = MappingSht.Range("B1").Value

sFilename = Worksheets("Summary").Range("A3").Value

ActiveWorkbook.SaveAs Filename:=MyFolderPath & sFilename & ".xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

Range("A1:A3").ClearContents

  ThisWorkbook.Worksheets("Summary").Range("A1:A3").ClearContents
Application.DisplayAlerts = True
End Sub
Hi,

ActiveWorkbook.SaveAs ... ".xlsm" perhaps?
EDIT: also change xlOpenXMLWorkbook to 52
 
Back
Top