Results 1 to 2 of 2
  1. #1
    WhatTheFrick is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2013
    Posts
    5

    Pass variables from Access to Excel

    Using Office 2007, mdb in 2003 format, Excel workbooks in 2003 format.

    I have been surprised to see no solution to this besides taking control of the Windows Clipboard.

    I'm trying to use a variable in Excel whose value was SET in Access. So in Access, I have code to open a workbook, and in Excel I have code to use values on a specific sheet, but the sheet name was set in an Access form.

    So, in Access I have a string variable (declared as Public) set to a form control's value (the following code might not be exactly right as I'm wrking from memory, but the SheetName variable IS getting set and the Excel Workbook IS opening and running my Excel code):

    Code:
    SheetName = Forms!FormName!Control value
    xlapp.open (Excel workbook)
    And in the Excel workbook I have code and a reference to the sheetname:

    Code:
    activeworkbook.sheets(SheetName).do something
    In Access, I can debug/print the SheetName variable and see it. In Excel, though, the SheetName variable is empty.
    How can I send this SheetName variable, with its value, to Excel? I tried using Global to declare it in Access and that didn't work either.

    This example is not my only need for this; I'm going to need to send several variables to Excel besides just sheetnames, so workarounds where I don't need to send this particular variable won't solve my issue.



    Any help on this would be appreciated. Thanks for reading.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    You can populate a cell in Excel with the value of the variable then the Excel code references the cell.
    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. Trouble defining variables - Access Module
    By David92595 in forum Modules
    Replies: 1
    Last Post: 11-29-2012, 07:09 PM
  2. Replies: 3
    Last Post: 10-20-2012, 11:52 AM
  3. Replies: 7
    Last Post: 02-20-2012, 07:19 PM
  4. Export a pass-through query to Excel
    By broon in forum Import/Export Data
    Replies: 0
    Last Post: 03-07-2011, 03:43 PM
  5. Replies: 10
    Last Post: 08-09-2010, 06:50 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