Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing New Workbook for Current

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hi

I'm using Excel 2003.

Sorry but I'm still confused on what to use when trying to apply something to the new workbook that I've saved versus the one that I'm copying.

Code:
Sub copyWorkbook()
    Application.ScreenUpdating = False
    Sheets(Array("wsA", "wsB", "wsC", "wsD")).Copy
    Application.DisplayAlerts = False
    Application.CutCopyMode = False
    If ThisWorkbook.Name = "E:\My Documents\MyFolder\WBCopy_" & Format(Now(), "YYYYMMDD") & ".xls" Then Exit Sub
    ActiveWorkbook.SaveCopyAs Filename"E:\My Documents\MyFolder\WBCopy_" & Format(Now(), "YYYYMMDD") & ".xls"
    Application.ScreenUpdating = True
End Sub

So now if I wish to reference the new worksheet of WBCopy is that the activeworkbook? Do I need to create a dimension and set the workbook as the file of "E:\My Documents\MyFolder\WBCopy_" & Format(Now(), "YYYYMMDD") & ".xls"?

All help greatly appreciated. Thanks.
 
A starting point:
Code:
Sub copyWorkbook()
Dim WBCopy As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ThisWorkbook.Sheets(Array("wsA", "wsB", "wsC", "wsD")).Copy
Set WBCopy = ActiveWorkbook
Application.CutCopyMode = False
WBCopy.SaveCopyAs Filename"E:\My Documents\MyFolder\WBCopy_" & Format(Now(), "YYYYMMDD") & ".xls"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



There should be no ambiguity with ThisWorkbook, so why the IF statement? ThisWorkbook is the one running the code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top