Results 1 to 3 of 3
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Excel object, copy and paste a worksheet

    Hello, Using Access VBA, within an Excel workbook, I need to copy the data on one worksheet to another worksheet. Here's the VBA behind a macro I created in Excel to do the copy and paste.

    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Sheets("ITS Active Employees").Select
    Range("A7").Select
    ActiveSheet.Paste



    I need assistance making this work within Access. Thanks in advance for your assistance!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Have to open the Excel app and file as VBA objects then can manipulate the objects. Review http://stackoverflow.com/questions/5...-in-access-vba

    Be sure to set VBA reference to MS Excel 14.0 Library.

    An issue I have encountered with trying to manipulate Excel from Access is that even after code runs successfully and the Excel app and file is closed, an Excel process may be left running in Task Manager. I am experiencing that now testing copy/paste code. Finally got this much to work:

    Dim oExcel As Excel.Application
    Dim oWb As Excel.Workbook
    Set oExcel = CreateObject("Excel.Application")
    Set oWb = oExcel.Workbooks.Open("C:\Users\June\LL\TournUmpir es.xlsx")
    oExcel.Visible = True
    oWb.Worksheets("TournUmps").Range("A1:B2").Copy
    oWb.Worksheets("Sheet1").Select
    oWb.Worksheets("Sheet1").Range("A7").Select
    oWb.Worksheets("Sheet1").Paste
    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.

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Thanks for the input. I was able to use your code as a start, and here's what I finished with.

    Dim xlApp As Object
    Dim wbExcel As Object

    'Set Excel Object
    Set xlApp = CreateObject("Excel.Application")
    'xlApp.Visible = True
    xlApp.DisplayAlerts = False

    'Set Object containing opened strFileName spreadsheet
    Set wbExcel = xlApp.Workbooks.Open(strWorkFile)

    'Manipulate spreadsheet file

    'Copy data from worksheet Sheet1
    wbExcel.Sheets("Sheet1").UsedRange.Copy

    'Paste data from worksheet Sheet1 into worksheet ITS Active Employees
    With wbExcel.Sheets("ITS Active Employees")
    .Select
    .Range("A7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With


    xlApp.DisplayAlerts = True

    'Close and Save Workbook
    xlApp.ActiveWorkbook.Close (True)

    'Close Excel Object
    xlApp.Quit

    'Clear Object variables
    Set wbExcel = Nothing
    Set xlApp = Nothing
    End Sub

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

Similar Threads

  1. Replies: 4
    Last Post: 12-19-2013, 01:18 PM
  2. Replies: 9
    Last Post: 06-21-2013, 08:22 PM
  3. How to copy and paste between worksheets in Excel?
    By Ronald Mcdonald in forum Programming
    Replies: 6
    Last Post: 05-26-2012, 10:40 PM
  4. Copy and Paste Format From Excel (attached)
    By KrenzyRyan in forum Import/Export Data
    Replies: 2
    Last Post: 01-02-2012, 05:56 PM
  5. COPY records from SUBFORM and PASTE to EXCEL?
    By taimysho0 in forum Programming
    Replies: 9
    Last Post: 11-28-2011, 02:45 PM

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