Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 AlanW wrote: 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. 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 AlanW wrote: 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Did you try the first suggestion?
And wb.sheet(1)... won't work. Did you mean to post wb.sheets(1)... AlanW wrote: 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. 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 AlanW wrote: 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 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy & paste cells fr open worksheet then close the worksheet | Excel Programming | |||
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 | Excel Worksheet Functions | |||
copy range on every worksheet (diff names) to a master worksheet (to be created) | Excel Programming | |||
copy range on every worksheet (diff names) to a master worksheet (to be created) | Excel Programming | |||
Code to copy range vs Copy Entire Worksheet - can't figure it out | Excel Programming |