PDA

View Full Version : Problem saving as macro-enabled workbook



Noivilbo
04-30-2010, 12:57 AM
Hi Guys,


I'm quite new to VBA, and I couldn't find the solution for the following problem;

I would like to create a new workbook with vba, move a sheet to the new workbook and then save it as a macro-enabled workbook.

I tried the following code:



Dim Newbook As Workbook
Set Newbook = Workbooks.ADD
Newbook.SaveAs Filename:="C:\Documents and Settings\" & Naamoud, FileFormat:=xlOpenXMLWorkbookMacroEnabled


I guess that the problem is that the Fileformat property is a read-only property?
In my variable "Naamoud", I have tried both with and without adding the ".xlsm", and I can't get it to work properly.


Thx in advance

Aussiebear
04-30-2010, 02:52 AM
This should give you an idea of the concept of saving as a macro enabled workbook. However you didn't say where the worksheet was to come from.

Sub Macro1()

ActiveWorkbook.SaveAs Filename:= _
"C:\Users\Ted\Documents\Saving as Macro Enabled.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub

Noivilbo
04-30-2010, 03:49 AM
The code above is indeed the one that i am trying to use (using a variable name and leaving out create-backup won't hurt I assume).

As you can see in the code, it is a new workbook.
Maybe I should modify something to the "Set Newbook = Workbooks.ADD"
to make it open a macro-enabled workbook immediately?

GTO
04-30-2010, 03:53 AM
No 2007 here, but what is the literal value of 'Naamoud'?

Mark

Noivilbo
04-30-2010, 04:38 AM
Value is "03.xlsm", but the error isn't there...
when I remove the .xlsm, I get an error that the file type mismatches because the extension is wrong..

GTO
04-30-2010, 04:51 AM
By chance, are you working in 2003, but wanting to save it in 2007 format? If so, change xlOpenXMLWorkbookMacroEnabled to 52.

Noivilbo
04-30-2010, 05:00 AM
Nono, I work in 2007 :)

Noivilbo
04-30-2010, 05:14 AM
goddamnit... i finally found out that the literal value was set to ".xlsx" somewhere else in the code, which i forgot.. now it works ofc..
(kinda weird because i remembered testing without the .xlsm added...)

sorry to bother you guys