Results 1 to 5 of 5

Code to open excel spreadsheet

  1. #1
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    18

    Code to open excel spreadsheet

    Good day, all.



    I'm a newbie and trying to open an excel spreadsheet with VBA code in a 2013 MS Access. Can someone help to provide the VBA code ?

    Appreciate your help.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,317
    By far the simplest way is to use application.followhyperlink , as this will use the windows default application for whatever the target file is;

    Code:
    Application.Followhyperlink "C:\ExcelStorage\MyExcelFile.xlsx"
    You can however use automation to open an excel application directly and do a lot more;

    Code:
       ' Late binding to avoid reference issues:
        Dim xlApp            As Object        'Excel.Application
        Dim xlWB             As Object        'Workbook
        Dim xlWS             As Object        'Worksheet
        Dim sFile             As String
        Dim sSheet          As String
    
        sFile = "C:\ExcelStorage\MyExcelFile.xlsx"
        sSheet = "MyWorkbookSheetName"
    
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = bOpen
        Set xlWB = xlApp.Workbooks.Open(sFile)
    
        Set xlWS = xlWB.Worksheets(sSheet)
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    18
    Thank you Minty, for your quick reply.

    Set xlWB = xlApp.Workbooks.Open(sFile)
    sFile = ????

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,317
    Quote Originally Posted by jtan View Post
    Thank you Minty, for your quick reply.

    Set xlWB = xlApp.Workbooks.Open(sFile)
    sFile = ????

    oops - sFile = "C:\ExcelStorage\MyExcelFile.xlsx"

    I've edited the original code post.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    18
    I'd tried it out. It works
    Thanks again, Minty

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

Similar Threads

  1. Replies: 6
    Last Post: 09-01-2018, 04:40 PM
  2. Replies: 1
    Last Post: 01-12-2016, 04:59 PM
  3. Replies: 2
    Last Post: 05-24-2015, 02:22 PM
  4. Adding VB Code to Excel spreadsheet from within Access
    By JonMulder in forum Programming
    Replies: 3
    Last Post: 05-01-2014, 02:30 PM
  5. Open Excel spreadsheet in Access
    By carlyd in forum Forms
    Replies: 1
    Last Post: 02-17-2012, 01:09 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
  •  
Tech Forums: Microsoft Office Forums