View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
SAMURA SAMURA is offline
external usenet poster
 
Posts: 8
Default Need a macro to copy a range in one workbook and paste into another workbook

Hi, Paul.

I could run that macro with no error.

Paul Maybe the differences are due to Excel Versions. I'm on XL 2K SR-1

Excel that could run the macro was Excel 2000 (9.0.4402 SR-1)
on the Windows 2000 SP4.
Is your Excel's version same?

Paul It cannot find "ITHD Monthly Calculator for reports V5.xls",

Perhaps, that macro does not recognize the path.
Then, how about trying to run this fixed macro?


Sub ITHDdocID2()
Dim rng As Range
Dim pastedBook As Workbook
Dim d As String

Windows("ITHD Reports.xls").Activate

Worksheets("ITHD").Range("A6").Select

'selected from ITHD!A6 to the end
Set rng = Range(Selection, Selection.End(xlDown))
rng.Select
rng.Copy

'fixed point 1
'reading the common path at the book "ITHD Reports.xls" and "ITHD Monthly
'Calculator for reports V5.xls"
d = ThisWorkbook.Path

'fixed point 2
'opened the book "ITHD Monthly Calculator for reports V5.xls"
'with the same path
Set pastedBook = Workbooks.Open(d & "\ITHD Monthly Calculator for reports
V5.xls")

'pasted to Time!A3
pastedBook.Worksheets("Time").Range("A3").PasteSpe cial xlPasteValues

'saved the book "ITHD Monthly Calculator for reports V5.xls"
pastedBook.Save

'closed the book "ITHD Monthly Calculator for reports V5.xls"
pastedBook.Close
Set pastedBook = Nothing

End Sub


--
Samura


"Paul" wrote in message
om...
Thanks for your efforts Samura.
I still see errors for some reason, with your code.
It cannot find "ITHD Monthly Calculator for reports V5.xls",
I overcome this, then it comes up with Compile error on the SAVE.

Maybe the differences are due to Excel Versions. I'm on XL 2K SR-1


"Samura" wrote in message

...
Hi.
It may be late, I fixed that macro.
This macro does not receive the error.
The macro opens the book "ITHD Monthly Calculator for reports V5.xls",
and pastes from "ITHD Reports.xls" to the book, and saves the book,
and closes the book.


Sub ITHDdocID()

Dim rng As Range
Dim pastedBook As Workbook

Windows("ITHD Reports.xls").Activate

Worksheets("ITHD").Range("A6").Select

'selected from ITHD!A6 to the end
Set rng = Range(Selection, Selection.End(xlDown))
rng.Select
rng.Copy

'opened the book "ITHD Monthly Calculator for reports V5.xls"
Set pastedBook = Workbooks.Open("ITHD Monthly Calculator for reports
V5.xls")

'pasted to Time!A3
pastedBook.Worksheets("Time").Range("A3").PasteSpe cial xlPasteValues

'saved the book "ITHD Monthly Calculator for reports V5.xls"
pastedBook.Save

'closed the book "ITHD Monthly Calculator for reports V5.xls"
pastedBook.Close
Set pastedBook = Nothing

End Sub