Name a New Workbook

  • Thread starter Thread starter Yuanhang
  • Start date Start date
Y

Yuanhang

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.
 
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
'<<============
 

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