if statement in macro
Posted by Steve on October 10, 2001 9:50 AM
I have a macro that opens a file (b) and then copies a sheet to it from the currently open file (a). My problem is that I want it work also if 1) the second file (b) is already open or if 2) the second file (b) already has a sheet by the same name as the one I am trying to copy to it.
Dim vendorbook, loc
loc = "C:\windows\desktop\pps\"
vendorbook = Range("b6").Text & ".xls"
'
Workbooks.Open Filename:=loc & vendorbook
'
Workbooks("PPSRetirement.xls").Activate
Worksheets("Reconcile").Copy After:=Workbooks(vendorbook).Worksheets("Introduction")
Workbooks(vendorbook).Activate
Worksheets("Reconcile").Activate
Dim vendor As String
vendor = Range("e1").Text
'
Sheets("reconcile").Name = vendor
'
Workbooks(vendorbook).Save
Workbooks(vendorbook).Close
thanks for any help with the code.
Steve