Solved

Excel VBA - Save a workbook as macro enabled

Posted on 2011-02-19
3
1,089 Views
Last Modified: 2012-06-21
How can I save a workbook as macro-enabled?

Here's my vba code that I tried (save with extension "xlsm") but doesn't work...  still tries to save as non-macro enabled.
Sub M_SaveAsMacroEnabled()

Dim v_TempFilePath as String
Dim v_TempFileName as String
Dim v_FileExtStr as String
Dim v_TimeStamp as String
Dim v_ReqName as String

    v_ReqName = [RangeReqName].value
    v_Location = [RangeLocation].value
    v_DateYYMMDD = [RangeDateYYMMDD].value
    v_TimeStamp = [RangeTimeStamp].value

    v_TempFilePath = ActiveWorkbook.Path & "\"
    v_FileExtStr = ".xlsm"  '//Save as macro-enabled workbook
    
    v_TimeStamp = Format(Now, "yymmddhhmm")
    
    v_TempFileName = "FirstPartOfMyFilename - " _
        & v_ReqName & " - " _  '//Next Part of the filename
        & v_Location & " - " _  '//Yet another part
        & v_DateYYMMDD & " - " _   '//And another      
        & v_TimeStamp            '//Last part before extension

    '//Save new file//
    
    With ActiveWorkbook
        .SaveAs ThisWorkbook.Path & "\" & TempFileName & _
            v_FileExtStr
        .ChangeFileAccess xlReadOnly
        Kill .FullName
        .Close False
    End With
    
End Sub

Open in new window

0
Comment
Question by:AndresHernando
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
patrickab earned 250 total points
ID: 34933447
AndresHernando,

Perhaps this sort of syntax would do the job:

ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\Patrick & Thuc-Nghi\My Documents\Patrick's\Excel files\Copy of daily-workbook_02.xlsm" _
        , FileFormat:=52, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False

Patrick
0
 

Author Closing Comment

by:AndresHernando
ID: 34933711
Worked great!  I needed to add the ", FileFormat:=52" after the extension.

Thanks!  --Andres
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34933719
Andres,

Pleased it solved the problem.

Thanks for the grade.

Patrick
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

777 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