Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set a Workbook Name from VB
Hi all,
I cannot manage to set a workbook name before save & close. This is my code: ###################################### Set appExcel = CreateObject("Excel.Application") With appExcel .WindowState = xlMaximized .SheetsInNewWorkbook = 3 .Add .DisplayAlerts = False End With appExcel.Workbooks(1).Name="MyFirstBook.xls" ###################################### Unfortunately, when executing the last instruction an error is raised, as this is a Read Only property. There's a default name which I need to custom, so I've searched for another one but they all seem to be Read Only ones!! How would you deal with it? Many thanks in advance. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set a Workbook Name from VB
Workbooks(1) is the first workbook opened, so if you are running your macro
from an Excel workbook and it is the first one opened, it will be workbooks(1). If you use the syntax: Workbooks.Add then you could use this from the VBA help files: Sub AddNew() Set NewBook = Workbooks.Add With NewBook .Title = "All Sales" .Subject = "Sales" .SaveAs Filename:="Allsales.xls" End With End Sub "Igum" wrote: Hi all, I cannot manage to set a workbook name before save & close. This is my code: ###################################### Set appExcel = CreateObject("Excel.Application") With appExcel .WindowState = xlMaximized .SheetsInNewWorkbook = 3 .Add .DisplayAlerts = False End With appExcel.Workbooks(1).Name="MyFirstBook.xls" ###################################### Unfortunately, when executing the last instruction an error is raised, as this is a Read Only property. There's a default name which I need to custom, so I've searched for another one but they all seem to be Read Only ones!! How would you deal with it? Many thanks in advance. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook | Excel Programming | |||
Select sheet tabs in workbook & save to separate workbook files | Excel Worksheet Functions | |||
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? | Excel Programming | |||
Copy a range of cells in an unopened workbook and paste it to the current workbook | Excel Programming | |||
What commands do you use to name a workbook, save a workbook,open a workbook | Excel Programming |