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.
|