+ Reply to Thread
Results 1 to 3 of 3

Coping Contents of one Sheet into Another Workbook

  1. #1
    Egon
    Guest

    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.


  2. #2
    Alok
    Guest

    RE: 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 Before:=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.
    >
    >


  3. #3
    Egon
    Guest

    Re: 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


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1