+ Reply to Thread
Results 1 to 2 of 2

Error when pasting a worksheet from one workbook into another

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    Venus, Tx
    MS-Off Ver
    Excel 2007
    Posts
    6

    Error when pasting a worksheet from one workbook into another

    I am trying to copy and paste a worksheet from one workbook that the user opens and paste it into another workbook in order to manipulate the data. The code is below:



    Private Sub JournalEntryTab_Click()

    ' This will open the data file selected and copy it into the template.

    Dim filename As Variant

    filename = application.GetOpenFilename("Excel Files (*.xls), *.xls")

    If filename <> False Then
    MsgBox "Open " & filename
    Workbooks.Open filename
    End If


    ' Copy and Past journal entry data into template worksheet
    Sheets("Report 1").Copy
    Windows("Depreciation Trend Monthly Template.xls").Activate
    Cells.Select
    Sheets("Depreciation Accum Detail").Paste ******This is where it errors******

    Thanks for any help!

  2. #2
    Registered User
    Join Date
    07-26-2012
    Location
    Venus, Tx
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Error when pasting a worksheet from one workbook into another

    I solved the issue. For anyone interested here is my code:

    ' This will open the data file selected and copy it into the template.

    Dim filename As Variant
    Dim CopySheet As Variant
    Dim PasteSheet As Variant

    filename = application.GetOpenFilename("Excel Files (*.xls), *.xls")

    If filename <> False Then
    MsgBox "Open " & filename
    Workbooks.Open filename
    End If


    ' Copy and Past journal entry data into template worksheet

    Set CopySheet = Sheets("Report 1")
    CopySheet.Activate
    CopySheet.Cells.Select
    selection.Copy

    Windows("Depreciation Trend Monthly Template.xls").Activate
    Set PasteSheet = Sheets("Depreciation Accum Detail")
    PasteSheet.Activate
    PasteSheet.Cells.Select
    ActiveSheet.Paste

+ 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