Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel VBA - Save a workbook as macro enabled

Posted on 2011-02-19
3
Medium Priority
?
1,121 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

660 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