Create a new workbook then rename without saving

  • Thread starter Thread starter Graham Whitehead
  • Start date Start date
G

Graham Whitehead

Does anyone know if it is possible to open a new workbook and rename it
without saving it using VBA?
 
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)
 
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?
 
Sub tester()
Dim wb As Workbook
Set wb = Workbooks.Add
<Your stuff here>
End Sub

HTH
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top