|
-
Jun 10th, 2010, 09:46 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Creating New Workbook
I am using Excel 2007.
My automation is set and basically updates the Template with new data every month when they open the workbook (after they receive an email that the data has been updated). It also has a combobox/button which allows them to display previous months' data on the Template.
I am trying to add an additional button which will create a new workbook and copy the report from the Template over to the new workbook. This way they can just send the relevant data to other people and not the Template which has all the macros and such.
Creating and copying is the easy part. However, every time I have the macro create a new workbook the name changes Book1, Book2, Book3, Book4, etc. Is there any way to name the new workbooks being created beforehand so the macro refers to the correct workbook? Or to store the name of the new workbook created into a variable so I can just reference that variable in the macro and it always refers to the correct one in cases where multiple workbooks are created?
-
Jun 10th, 2010, 09:54 AM
#2
Re: Creating New Workbook
This way of creating a new workbook involves assigning it to an object variable. In the code below, the Workbook object returned by the Add method is assigned to an object variable, XLBook. Next, then new name of XLBook is set. You can easily control the new workbook using the object variable.
Code:
Sub AddNew()
Set XLBook = Workbooks.Add
With XLBook
.SaveAs Filename:="MyFile.xls"
End With
End Sub
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 10th, 2010, 10:13 AM
#3
Thread Starter
Hyperactive Member
Re: Creating New Workbook
Awesome, this works greats. It automatically saves it to the desktop, right?
-
Jun 10th, 2010, 10:19 AM
#4
Re: Creating New Workbook
No, I believe it saves to my documents. You will have to specify the path for example...
Code:
Sub AddNew()
Set XLBook = Workbooks.Add
With XLBook
.SaveAs Filename:="C:\MyFFile.xls"
End With
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|