Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / June 2006

Tip: Looking for answers? Try searching our database.

Create a new workbook then rename without saving

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Graham Whitehead - 14 Jun 2006 13:51 GMT
Does anyone know if it is possible to open a new workbook and rename it
without saving it using VBA?
Bob Phillips - 14 Jun 2006 14:39 GMT
Even without opening it

Dim OldName, NewName
OldName = "OLDFILE"
NewName = "NEWFILE"
Name OldName As NewName

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

> Does anyone know if it is possible to open a new workbook and rename it
> without saving it using VBA?
Graham Whitehead - 15 Jun 2006 11:03 GMT
This only works when I know the name of the workbook I am renaming.  When I
create a new workbook it gets named 'Book x' where x indicates how many have
been created in the current excel session.  I have no way to track the value
of x - therefore I am unable to reference the old name.

I am creating a new workbook from scratch and collecting data from various
other workbooks and adding them into this new workbook as new worksheets.
Therefore, I need a way of referencing the newly created workbook every time
I need it.  Does this make sense?

> Even without opening it
>
[quoted text clipped - 13 lines]
>> Does anyone know if it is possible to open a new workbook and rename it
>> without saving it using VBA?
Ardus Petus - 15 Jun 2006 11:10 GMT
Sub tester()
Dim wb As Workbook
Set wb = Workbooks.Add
<Your stuff here>
End Sub

HTH
--
AP

> This only works when I know the name of the workbook I am renaming.  When
> I create a new workbook it gets named 'Book x' where x indicates how many
[quoted text clipped - 23 lines]
>>> Does anyone know if it is possible to open a new workbook and rename it
>>> without saving it using VBA?
Graham Whitehead - 15 Jun 2006 11:22 GMT
Hi, thanks for the input.  However, I am getting an object required error
here.  Using the code that you gave me how do I name the workbook that is
creates.  For example I am using this:

Dim wb As Workbook

   strNewWBName = strCountry & " Checking Workbook"

   Set wb = Workbooks.Add
   Workbook.Name = strNewWBName

> Sub tester()
> Dim wb As Workbook
[quoted text clipped - 33 lines]
>>>> Does anyone know if it is possible to open a new workbook and rename it
>>>> without saving it using VBA?
Bob Phillips - 15 Jun 2006 15:44 GMT
If you are creating a  new workbook from scratch, you cannot rename it until
it has been saved. Therefore, when adding the workbook you should set a
variable to that workbook, and use that variable throughout

Dim oWB AsWorkbook

   Set oWB = Workbooks.Add
   .
' do some stuff

   oWB.SaveAs Filename:= "C:\MyDir\MyTest.xls"
   oWB.Close

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

> This only works when I know the name of the workbook I am renaming.  When I
> create a new workbook it gets named 'Book x' where x indicates how many have
[quoted text clipped - 23 lines]
> >> Does anyone know if it is possible to open a new workbook and rename it
> >> without saving it using VBA?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.