Link to home
Start Free TrialLog in
Avatar of AndresHernando
AndresHernando

asked on

Excel VBA - Save a workbook as macro enabled

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

ASKER CERTIFIED SOLUTION
Avatar of patrickab
patrickab
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AndresHernando
AndresHernando

ASKER

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

Thanks!  --Andres
Andres,

Pleased it solved the problem.

Thanks for the grade.

Patrick