ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Coping Contents of one Sheet into Another Workbook (https://www.excelbanter.com/excel-programming/347060-coping-contents-one-sheet-into-another-workbook.html)

Egon

Coping Contents of one Sheet into Another Workbook
 
I have a need to build a Macro that will take an excel file (Which the
user specifies) and copies the contents of the second sheet (With a
specific name) into another workbook putting specific cells in specific
places in the second workbook. Then I need it to rename the file so we
know that the file has been input.

I'm not even sure where to start, I'm sure I can get the pieces for the
copying and pasting, but how to handle the file and such is going to be
a bit more difficult for me.

Can anyone lend a hand in leading me in the right direction?

TIA
J.


Alok

Coping Contents of one Sheet into Another Workbook
 
Hi
Try the following routines.

Function OpenWorkbook(ByRef wb As Workbook) As Boolean

Dim v As Variant

On Error GoTo OpenWorkbookError
v = Application.GetOpenFilename(FileFilter:="(*.xls),* .xls")
If TypeName(v) = "Boolean" Then
'User Cancelled
GoTo OpenWorkbookError
Else
Set wb = Application.Workbooks.Open(v)
End If
OpenWorkbook = True

Exit Function
OpenWorkbookError:
OpenWorkbook = False

End Function

Function CopyWorkbook()
Dim wb As Workbook
Dim wbNew As Workbook
Dim wsNew As Worksheet

If OpenWorkbook(wb) Then
'do something
Set wbNew = Workbooks.Add
'The worksheet you want to copy will replace
'abc below.
wb.Worksheets("abc").Copy Befo=wbNew.Worksheets(1)
Set wsNew = ActiveSheet

'To copy specific cells to the new worksheet created
'in the new workbook(now called wsNew) you do the following
wsNew.Cells(1, 1).Value = wb.Worksheets("pqr").Cells(1, 1).Value

'do other processing
wbNew.Close SaveChanges:=True
wb.Close SaveChanges:=True
End If
End Function

Alok

"Egon" wrote:

I have a need to build a Macro that will take an excel file (Which the
user specifies) and copies the contents of the second sheet (With a
specific name) into another workbook putting specific cells in specific
places in the second workbook. Then I need it to rename the file so we
know that the file has been input.

I'm not even sure where to start, I'm sure I can get the pieces for the
copying and pasting, but how to handle the file and such is going to be
a bit more difficult for me.

Can anyone lend a hand in leading me in the right direction?

TIA
J.



Egon

Coping Contents of one Sheet into Another Workbook
 
I think I get part of what you are doing here, the only problem is that
the form was created by someone else (The excel worksheet that I'm
copying FROM) and I don't want the format of the cells, I just need the
data IN the cells. But I think I can get that if I can get it opened
and Closed.

Let me try this and see how it goes.

Thanks a ton.
J



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com