Results 1 to 2 of 2
  1. #1
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56

    copy sheet from closed workbook into an open workbook

    I am trying to copy a worksheet from a closed workbook into an open workbook but it is not working. I don't get any error but nothing happens. Please see my code comments also.

    Code:
    Set xlWrkBk2 = Workbooks.Open("M:\BSC Benefits\Benefits Tickets\" & Format(Date, "YYYY_MM_DD") & "Empire Report.xlsx")
    xlWrkBk2.UnProtect
    xlWrkBk2.UnprotectSharing
    Set targetBk = ActiveWorkbook                                                                                         'This should be the workbook I just opened above rihgt?
    
    
    Set getReconFile = Application.FileDialog(msoFileDialogOpen)                                                   'open a file dialog to choose the workbook that has the sheet(s) I want to copy
    With getReconFile
    .Show
       Set reconBk = GetObject(getReconFile)
       
      For Each Sheet In reconBk.Sheets
            If Sheet.Visible = True Then
                Sheet.Copy After:=targetBk.Sheets(targetBk.Sheets.count)                                          'copy the sheet from the file I just selected and add it as the last sheet of file opened earlier.
                
                ActiveSheet.Name = "Sub-Group Translator"                                                                'give a name to the sheet that I just copied over
          '  End If
        'Next Sheet
    'End With
    
    
    xlWrkBk2.Save                                                                                                                     'Save WorkBook
     xlWrkBk2.Close                                                                                                                   'Close WorkBook


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why are the 3 lines of the With, For, If code commented out?

    This works for me:
    Dim exl As Excel.Application
    Dim wkbSource As Excel.Workbook
    Dim wkbDest As Excel.Workbook
    Set exl = CreateObject("Excel.Application")
    Set wkbSource = exl.Workbooks.Open("C:\Temp\Test1.xlsx")
    Set wkbDest = exl.Workbooks.Open("C:\Temp\Test2.xlsx")
    wkbSource.Sheets("Sheet1").Copy After:=wkbDest.Sheets(wkbDest.Sheets.Count)
    wkbDest.Save
    wkbDest.Close
    wkbSource.Close
    exl.Quit
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 07-22-2013, 01:11 PM
  2. New workbook/worksheets using Transfer Spreadsheet
    By nyneave in forum Import/Export Data
    Replies: 3
    Last Post: 09-05-2012, 06:44 PM
  3. Replies: 2
    Last Post: 08-14-2012, 04:24 AM
  4. Link to Excel Workbook
    By Shelly9633 in forum Access
    Replies: 2
    Last Post: 01-06-2012, 10:43 AM
  5. Get column headings from closed Workbook
    By Deutz in forum Access
    Replies: 1
    Last Post: 12-10-2010, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums