Results 1 to 5 of 5
  1. #1
    Kovenna is offline Novice
    Windows 11 Office 365
    Join Date
    Jun 2024
    Posts
    1

    How to link to a named range in an excel spreadsheet using vba code

    Can someone help?

    I have been trying to do this for hours with no success.



    I would like to use Docmd.TransferSpreadsheet but

    1. I have to specify IMX = 0 otherwise I cannot update data in the linked table
    2. I have no idea how to reference the named range in TransferSpreadsheet.

    Ideally I would like to use the full connection string in a function then I should have access to all the various parts for the connection string

    Thanks for your help in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you must connect the entire sheet.
    you could have another sheet that points to the named range values in the other.

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Which side is doing the work, Excel or Access? You're supposed to be able to use a named range if you import while in Access. Does this help:
    https://learn.microsoft.com/en-us/of...ferspreadsheet

    There is also Automation if all else fails.
    http://www.accessmvp.com/KDSnell/EXCEL_MainPage.htm
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can link to a named range. Syntax for TransferSpreadsheet:

    "SheetName!RangeName"

    Yes, use ! in TransferSpreadsheet command which will create a link that has $ character. Weird but true.

    Once link is established, IMEX can be modified with VBA and TableDefs.

    However, I am getting odd behavior with my testing. I cannot establish link with named range using TransferSpreadsheet unless the workbook is open. This is very odd.

    Or build a query object with parameters. Example.
    Code:
    SELECT * FROM [Units$] IN 'C:\Users\June\Condos.xlsx'[Excel 12.0;HDR=yes;IMEX=0;ACCDB=Yes;TABLE=Units$Print_Area];
    Last edited by June7; 06-17-2024 at 11:58 PM.
    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.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2019, 08:35 AM
  2. Import from Excel, using a Named range for control
    By Western_Neil in forum Import/Export Data
    Replies: 15
    Last Post: 01-22-2019, 06:57 PM
  3. Replies: 5
    Last Post: 08-26-2018, 07:54 PM
  4. Replies: 3
    Last Post: 08-15-2012, 04:15 PM
  5. How to import named range from excel
    By timpepu in forum Import/Export Data
    Replies: 1
    Last Post: 02-19-2010, 11:26 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