Solved

Excel VBA - Save a workbook as macro enabled

Posted on 2011-02-19
3
1,109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

759 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