SaveAs without closing original workbook

  • Thread starter Thread starter Stefi
  • Start date Start date
S

Stefi

Hi All,

I want to clone a workbook in several copies with different file names, and
also I want to keep the original workbook open during the process and
activate it again at the end of the process. SaveAs works, but closes the
original.

Thanks,
Stefi
 
I forgot to mention that the workbook to be cloned contains the cloning Sub,
so Thisworkbook is to be cloned!

Stefio


„Stefi†ezt írta:
 
Adapt something like the following, if testing in a new wb first run Sub
origName()

Sub origName()
ThisWorkbook.SaveAs "TestOrig.xls"
End Sub

Sub test()
Dim sPath As String
Dim bKeepOpen
Const cOrigName As String = "TestOrig.xls" ' << change to the default name

bKeepOpen = True

If ThisWorkbook.Name = cOrigName Then
ThisWorkbook.Save
sPath = ThisWorkbook.Path & "\" & _
Replace(ThisWorkbook.Name, ".xls", "", , , vbTextCompare) & "_"
Application.DisplayAlerts = False
For i = 1 To 3
ThisWorkbook.SaveAs sPath & MonthName(i, True) & ".xls"
Next
ThisWorkbook.SaveAs cOrigName

If bKeepOpen Then
For i = 1 To 3
Workbooks.Open sPath & MonthName(i, True) & ".xls"
Next
End If

End If
Application.DisplayAlerts = True
End Sub

Save with as many names as you need, then re-save with the original name,
optionally reopen the others.

Regards,
Peter T
 
Thanks Ron and Peter! Peter's solution works, but Ron's one is really much
nicer!
Stefi


„Peter T†ezt írta:
 

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