Results 1 to 6 of 6
  1. #1
    stu is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    13

    How to open an Excel file from Access 2010?

    Hi,



    I need to open an excel *.xlsx file from Access 2010 using a macro or VBA but can't get any of the examples on various forums to work. Please help.

    Thanks in advance.

    Stu

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Why can't you get code to work - error message, wrong results, nothing? What methods have you attempted? Show the code so we can analyse.
    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
    stu is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    13
    Hi, nothing happens at all. The code is -

    Code:
    Private Sub Command273_Click()
    
    Dim xl As Excel.Application
    Dim wbk As Excel.Workbook
    Dim wsht As Excel.Worksheet
    Dim filename As String
    Dim lastRow As Integer
           
    Set xl = New Excel.Application
    xl.DisplayAlerts = False
    Set wbk = xl.Workbooks.Add("path\filename.xlsx")
    
    End Sub
    This is just a piece of code I picked up from a forum search. Can you tell me how you would go about opening an excel file by clicking a button in Access 2010?

    Many thanks,

    Stu

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Depends on what you want to do with the open workbook.

    If you just want to open the same workbook every time, then can be done as a hyperlink. Use the HyperlinkAddress property of a command button. Put the path to the file, like: D:\LL\TournUmpires.xlsx. Put whatever you want in the Caption. If you want to dynamically open variety of workbooks, review http://allenbrowne.com/func-GoHyperlink.html

    If you want to open the workbook and have Access write data to/from cells, that requires opening an Excel object and code will manipulate the Excel object. It is this situation that your code is for. Need to use the actual drive and path and filename for your workbook in place of the generic example in the code. Will also have to set a VBA reference to: Microsoft Excel 14.0 Object Library. I tested the procedure (with my drive\path\filename as shown in previous paragraph) and it does open an instance of Excel as can be seen in the Windows Task Manager. The app just isn't visible. Need line in code: xl.Visible = True
    Review http://forums.aspfree.com/microsoft-...el-414974.html
    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
    stu is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    13
    Sorted. Thank you June7!

  6. #6
    squatter is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    2
    Thank you sir. it really help....

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

Similar Threads

  1. Get current record when open an excel file
    By majinon2012 in forum Programming
    Replies: 1
    Last Post: 06-12-2012, 10:32 AM
  2. Open Excel .xlsx file from Access
    By Bigmix in forum Programming
    Replies: 6
    Last Post: 02-28-2012, 09:55 AM
  3. to open Exported Excel File
    By waqas in forum Programming
    Replies: 3
    Last Post: 10-16-2011, 12:33 PM
  4. Open excel file in access
    By shanky365 in forum Access
    Replies: 1
    Last Post: 09-11-2011, 03:05 PM
  5. How to open a word/excel/other file in vba
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-28-2010, 10:36 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