Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Copying a worksheet

Hi Robin,

Thanks a lot for the reply.
I just tried this, and it worked for me.

Sub CopyFromSoure()

Workbooks.Open Filename:=ActiveWorkbook.Path & "\Test2.xls"
Workbooks("Test2.xls").Worksheets("Sheet1").Range( "A:IV").Copy
ActiveSheet.Paste Destination:=ThisWorkbook.Worksheets(2).Range("A1" )
Application.CutCopyMode = False
Workbooks("Test2.xls").Close savechanges:=False

End Sub

Thanks.
"Robin Hammond" wrote:

Rain,

Try something like this. I haven't tried to perfect it but it seems to work.

Sub CopyBook()
Dim SourceWkbk As Workbook
Dim wbTgt As Workbook
Dim shTgt As Worksheet
Set wbTgt = ActiveWorkbook
Set SourceWkbk = Workbooks.Open(Filename:="C:\book1.xls")
Sheets("Sheet3").Copy After:=wbTgt.Sheets(wbTgt.Sheets.Count)
wbTgt.Sheets(wbTgt.Sheets.Count).Visible = xlSheetHidden
SourceWkbk.Close savechanges:=False
End Sub

Robin Hammond
www.enhanceddatasystems.com

"Rain" wrote in message
...
I am trying to do the following using VBA:
1. Open a workbook
2. Copy a sheet
3. Paste it on a destination WorkBook.Sheet where this sheet it hidden
4. Close the source workbook

I tried the following:
Sub Copyfromworkbook()

Dim SourceWkbk As Workbook
Set SourceWkbk = Workbooks.Open(Filename:="Book2.xls")
SourceWkbk.Sheets("Sheet3").Copy

' ActiveSheet.Paste Destination:=Sheets("Sheet4").Range("A1")
Sheets("Sheet4").Range("A1").Select
ActiveSheet.Paste

SourceWkbk.Close savechanges:=False

End Sub

I get a subscript out of range error.
Can you please tell me where I am going wrong.




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
Worksheet formula incorrect after copying to another worksheet Karen Excel Worksheet Functions 2 November 12th 09 01:06 AM
Copying worksheet cells into another worksheet using autofill SunnySD Excel Discussion (Misc queries) 3 September 10th 08 10:32 PM
Looking up a variable in one worksheet and copying information from another column to another worksheet?? Brad Torken Excel Discussion (Misc queries) 2 December 10th 06 06:02 AM
Copying a worksheet witrh protected cells to a new worksheet John Excel Worksheet Functions 2 February 1st 06 02:19 PM
Copying Worksheet triggers Click event of combobox on another worksheet Robert[_20_] Excel Programming 0 January 23rd 04 07:40 PM


All times are GMT +1. The time now is 03:25 PM.

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"