Unable to copy another spreadsheet to the current spreadsheet with

G

Guest

I turned on the macro recorder on the current spreadsheet and called up
another spreadsheet, selected All, and pasted to the current spreadsheet
successfully. When I played back the macro, I got this message:

Select Method of Range Class failed:

The code is listed below and the error occured at Cells.Select:

ChDir "T:\ArchivePandL's"
Workbooks.Open Filename:="T:\ArchivePandL's\PL09-05.xls", UpdateLinks:=0
Selection.Copy
Windows("BchPerAuto1.xls").Activate
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Monthly").Select
Cells.Select
Range("E1").Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
 
G

Guest

rmcompute:

Add a VBA module to your project and add this code to it.

Set wbk = Workbooks.Open(Filename:="T:\ArchivePandL's\PL09-05.xls",
UpdateLinks:=0)
'PL09-05.xls if copy Sheet1!A1:10
wbk.Sheets("Sheet1").Range("A1:A10").Copy
With ThisWorkbook.Sheets("Monthly").Range("E1")
.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
 
G

Guest

It worked.

Thank you.

chijanzen said:
rmcompute:

Add a VBA module to your project and add this code to it.

Set wbk = Workbooks.Open(Filename:="T:\ArchivePandL's\PL09-05.xls",
UpdateLinks:=0)
'PL09-05.xls if copy Sheet1!A1:10
wbk.Sheets("Sheet1").Range("A1:A10").Copy
With ThisWorkbook.Sheets("Monthly").Range("E1")
.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False

--
天行å¥ï¼Œå›å­ä»¥è‡ªå¼·ä¸æ¯
地勢å¤ï¼Œå›å­ä»¥åŽšå¾·è¼‰ç‰©

http://www.vba.com.tw/plog/
 

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

Top