Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / August 2007

Tip: Looking for answers? Try searching our database.

Copy worksheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AlanW - 26 Aug 2007 02:12 GMT
I would like to copy a worksheet from FileA to FileB by using the listed
code, but it is strange that the result is just the opposite; it copies FileB
to FileA.  Could someone please help.

The codes are as follows:-

Sub test()
Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.ActiveSheet
Set wb = Workbooks.Open("C\FileB.xls")

wb.Sheets(1).Range("A1").Copy
ws.Range("A!").PasteSpecial xlPasteValues

wb.Close Savechanges:=False
End Sub

Thanks
Dave Peterson - 26 Aug 2007 02:35 GMT
First, you should post the code that you're using instead of typing it into the
post.

Sub test()
Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.ActiveSheet
Set wb = Workbooks.Open("C\FileB.xls")  '<-- this won't work

ws.range("a1").copy
wb.sheets(1).range("a1").pastespecial paste:=xlpastevalues

'you sure you want to close FileB without saving?
wb.Close Savechanges:=False  

End Sub

> I would like to copy a worksheet from FileA to FileB by using the listed
> code, but it is strange that the result is just the opposite; it copies FileB
[quoted text clipped - 15 lines]
>
> Thanks

Signature

Dave Peterson

AlanW - 26 Aug 2007 13:36 GMT
Hi Dave,

Thank you for your reply first.

I posted below the whole code for your reference,  please help me to solve
the problem

Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.ActiveSheet
Set wb = Workbooks.Open("F:\All MS Office Files\Sample Official.xls")

ws.Range("A1:I14").Copy
wb.Sheet(1).Range("M2").PasteSpecial xlPasteValues

"Dave Peterson" 來函:

> First, you should post the code that you're using instead of typing it into the
> post.
[quoted text clipped - 32 lines]
> >
> > Thanks
Dave Peterson - 26 Aug 2007 15:47 GMT
Did you try the first suggestion?

And wb.sheet(1)... won't work.  Did you mean to post wb.sheets(1)...

> Hi Dave,
>
[quoted text clipped - 53 lines]
> >
> > Dave Peterson

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.