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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro Code Help Required 1

Status
Not open for further replies.

Sech

Programmer
Jul 5, 2002
137
GB
Please help if you can. I have two spreadsheets and I want to copy the data from one into the other using copy and paste. I want to do this automatically from within Access.The code I have got is as follows:

Set oxlTemplateBook = oxlApp.Workbooks.Open("trending.xls")
Set oxlWorkbook = oxlApp.Workbooks.Open(sFilePath)
Set oxlWorksheet = oxlWorkbook.Sheets("qryTrdAvContractMileageToForeca")
oxlWorksheet.Columns("A:C").Select
oxlApp.Selection.Copy
oxlApp.Windows("Trending.xls").Activate
Set oxlTemplateSheet = oxlTemplateBook.Sheets("Contract To Forecast Data")
oxlTemplateSheet.Columns("A:C").Select
oxlApp.Selection.Paste

However when it gets to the second columns selection line an error occurs saying "Select method of range class failed"

What am I doing wrong?
 
I'm not sure, but you might be better off, just selecting A1 cell on you destination sheet and letting Excel deal with the expansion.
I have found that sometimes excel does not like it when I try to help, that its better doing the minimum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top