PDA

View Full Version : Naming a new WorkBook



Rasm
05-03-2011, 04:49 AM
Below is the code I use to add a new workbook - but How can I assign a name to the new workbook - If I try to use the .Name property - I am told readOnly. Any help is appreciated.



Dim NewBookX As Workbook
Set NewBookX = Workbooks.Add

Admin
05-03-2011, 12:40 PM
Hi,

Would this work ?


Dim NewBookX As Workbook
Set NewBookX = Workbooks.Add

If NewBookX.ReadOnly Then
NewBookX.ChangeFileAccess Mode:=xlReadWrite
NewBookX.Name = "NewName"
End If

Rasm
05-03-2011, 04:22 PM
ahhh - great - thanks

Excel Fox
05-03-2011, 07:52 PM
Try this....



Dim wbkNew As Workbook
Workbooks.Add(xlWorksheet).SaveAs Filename:="NewName", FileFormat:=&H34 '33 = XLSX, 34 = XLSM
Set wbkNew = Workbooks("NewName.xlsm")
With wbkNew
.ChangeFileAccess xlReadOnly
Kill .FullName
End With

Rasm
05-04-2011, 04:12 AM
Will do - the other one did not like a full compile - thanks