Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Opening and pasting in active workbook

I am having trouble pasting the data from an opened .xls file into the
current sheet I am on.
I have opened the workbook I need, and then I am attempting to paste
the data into the workbook I am currently using. I have no trouble
pasting the data into a different sheet on the workbook, just not the
worksheet titled 'targetrenewal'.

Does anyone know what I am doing wrong?

Thanks!

Sub PW_Open()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"
Set Wb2 = Workbooks.Open("C:\target rent\pw_targetrent.xls")
Wb2.Sheets("Sheet1").Copy _
Destination:=Wb1.Worksheets("TargetRenewal") ****this gives an
error 'Application-defined or Object-defined Error'*****
Wb2.Close False
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Opening and pasting in active workbook

After you open the 2nd workbook (it is the active workbook now) use the
following to copy the entire sheet

Sheets("Sheet1").Activate
Cells.Copy Destination:=Wb1.Sheets("TargetRenewal").Range("A1 ")

I could not get it to copy to the destination using references! but you do
need to specify the destination range it seems.
Hope this helps

Cheers
Nigel

"TR" wrote in message
om...
I am having trouble pasting the data from an opened .xls file into the
current sheet I am on.
I have opened the workbook I need, and then I am attempting to paste
the data into the workbook I am currently using. I have no trouble
pasting the data into a different sheet on the workbook, just not the
worksheet titled 'targetrenewal'.

Does anyone know what I am doing wrong?

Thanks!

Sub PW_Open()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"
Set Wb2 = Workbooks.Open("C:\target rent\pw_targetrent.xls")
Wb2.Sheets("Sheet1").Copy _
Destination:=Wb1.Worksheets("TargetRenewal") ****this gives an
error 'Application-defined or Object-defined Error'*****
Wb2.Close False
Application.ScreenUpdating = True
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Opening and pasting in active workbook

Hi TR,

Wb2.Sheets("Sheet1").Copy _
Destination:=Wb1.Worksheets("TargetRenewal")


You have not defined the range that you want to copy and you have not
defined a target range.

Assuing that you want to copy the range "A1:D100" from Sheet1 in
TargetRent.xls to the TargetRenewal sheet in the active workbook, then
change the above line to:

Wb2.Sheets("Sheet1").Range("A1:D100").Copy _
Destination:=Wk1.Range("A1")

If, alternatively, you want to copy the whole sheet, this becomes:

Wb2.Sheets("Sheet1").UsedRange.Copy _
Destination:=Wk1.Range("A1")

Amend the two ranges to suit your needs.

Incidentally, I have replaced

Wb1.Worksheets("TargetRenewal")

with

Wk1

as you have already assigned the sheet to this object variable. It is not
wrong to refer to the worksheet in the first way, it is merely unnecessary.


---
Regards,
Norman



"TR" wrote in message
om...
I am having trouble pasting the data from an opened .xls file into the
current sheet I am on.
I have opened the workbook I need, and then I am attempting to paste
the data into the workbook I am currently using. I have no trouble
pasting the data into a different sheet on the workbook, just not the
worksheet titled 'targetrenewal'.

Does anyone know what I am doing wrong?

Thanks!

Sub PW_Open()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"
Set Wb2 = Workbooks.Open("C:\target rent\pw_targetrent.xls")
Wb2.Sheets("Sheet1").Copy _
Destination:=Wb1.Worksheets("TargetRenewal") ****this gives an
error 'Application-defined or Object-defined Error'*****
Wb2.Close False
Application.ScreenUpdating = True
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Opening and pasting in active workbook

Thanks!!!! It works great!!!!


"Norman Jones" wrote in message ...
Hi TR,

Wb2.Sheets("Sheet1").Copy _
Destination:=Wb1.Worksheets("TargetRenewal")


You have not defined the range that you want to copy and you have not
defined a target range.

Assuing that you want to copy the range "A1:D100" from Sheet1 in
TargetRent.xls to the TargetRenewal sheet in the active workbook, then
change the above line to:

Wb2.Sheets("Sheet1").Range("A1:D100").Copy _
Destination:=Wk1.Range("A1")

If, alternatively, you want to copy the whole sheet, this becomes:

Wb2.Sheets("Sheet1").UsedRange.Copy _
Destination:=Wk1.Range("A1")

Amend the two ranges to suit your needs.

Incidentally, I have replaced

Wb1.Worksheets("TargetRenewal")

with

Wk1

as you have already assigned the sheet to this object variable. It is not
wrong to refer to the worksheet in the first way, it is merely unnecessary.


---
Regards,
Norman



"TR" wrote in message
om...
I am having trouble pasting the data from an opened .xls file into the
current sheet I am on.
I have opened the workbook I need, and then I am attempting to paste
the data into the workbook I am currently using. I have no trouble
pasting the data into a different sheet on the workbook, just not the
worksheet titled 'targetrenewal'.

Does anyone know what I am doing wrong?

Thanks!

Sub PW_Open()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"
Set Wb2 = Workbooks.Open("C:\target rent\pw_targetrent.xls")
Wb2.Sheets("Sheet1").Copy _
Destination:=Wb1.Worksheets("TargetRenewal") ****this gives an
error 'Application-defined or Object-defined Error'*****
Wb2.Close False
Application.ScreenUpdating = True
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting active links in excel Horse Excel Discussion (Misc queries) 0 March 5th 10 11:43 PM
pasting textbox value to active cell ASU Excel Discussion (Misc queries) 2 June 23rd 06 03:58 PM
Active Cell when opening workbook mwclark0807 Excel Worksheet Functions 3 January 5th 06 04:38 AM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM
Preventing opening workbook inside active workbook. Serge[_4_] Excel Programming 2 November 4th 03 07:51 PM


All times are GMT +1. The time now is 11:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"