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 / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Name a New Workbook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yuanhang - 30 May 2008 03:21 GMT
In a macro, I have a main workbook open where I run the Macro.

What I want the macro to do is adding a few new workbooks (around 10 new
workbooks), and then name them according to a list of names (F2:F11) in the
main workbook.

Is there any way to guide me to this? Thank you.
Norman Jones - 30 May 2008 03:37 GMT
Hi Yuanhang,

In a standard module, try:

'============>>
Option Explicit
Public Sub Tester001()
   Dim WB As Workbook
   Dim newWB As Workbook
   Dim SH As Worksheet
   Dim Rng As Range
   Dim rCell As Range

   Set WB = Workbooks("myBook.xls")   '<<===== CHANGE
   Set SH = WB.Sheets("Sheet1")             '<<===== CHANGE
   Set Rng = SH.Range("F2:F11")              '<<===== CHANGE

   On Error GoTo XIT
   Application.ScreenUpdating = False

   For Each rCell In Rng.Cells
       Set newWB = Workbooks.Add
           With newWB
               .SaveAs Filename:=rCell.Value, _
                       FileFormat:=xlWorkbookNormal
               .Close SaveChanges:=False
           End With
   Next rCell

XIT:
   Application.ScreenUpdating = True

End Sub
'<<============

---
Regards.
Norman
> In a macro, I have a main workbook open where I run the Macro.
>
[quoted text clipped - 4 lines]
>
> Is there any way to guide me to this? Thank you.
 
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.