Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM
Select sheet tabs in workbook & save to separate workbook files stratocaster Excel Worksheet Functions 2 March 1st 06 03:35 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Excel Programming 9 July 25th 05 12:44 PM
Copy a range of cells in an unopened workbook and paste it to the current workbook topstar Excel Programming 3 June 24th 04 12:50 PM
What commands do you use to name a workbook, save a workbook,open a workbook Steven R. Berke Excel Programming 1 July 24th 03 11:37 PM


All times are GMT +1. The time now is 04:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"