copy data from one workbook to another using macro


Posted by Lee on September 21, 2000 12:53 PM

I use a macro to copy data from one workbook (History.xls) to another (corvette.xls) as shown below. Can I use another command to paste the data onto the "Corvette.xls" workbook. My problem is if I rename "Corvette.xls" my macro will no longer work.


Workbooks.Open Filename:="\\test\port\History.xls"
Range("A1:K60000").Select
Selection.Copy
Windows("corvette.xls").Activate
Application.Goto Reference:="historicaltradespointer"
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A24").Select
Windows("TradeHistory.xls").Activate
ActiveWorkbook.Close



Posted by Celia on September 21, 2000 5:33 PM

Lee
If you have the Corvette workbook as the active workbook when you run your macro, you can avoid putting the workbook name in the macro as follows :-

Dim wb As Workbook
Set wb = ThisWorkbook
Workbooks.Open Filename:="\\test\port\History.xls"
Range("A1:K60000").Select
Selection.Copy
wb.Activate
Application.Goto Reference:="historicaltradespointer"
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A24").Select
Windows("TradeHistory.xls").Activate
ActiveWorkbook.Close

You can re-name your Corvette workbook and the macro will still work.

Celia