Solved

Excel VBA - Save a workbook as macro enabled

Posted on 2011-02-19
3
1,078 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now