Results 1 to 7 of 7
  1. #1
    Bigmix is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    11

    Open Excel .xlsx file from Access

    I had the following code that works perfectly for .xls files by running CmdOpenExcel () macro:



    Private Sub CmdOpenExcel_Click()
    Function CmdOpenExcel()
    'Williford - opens the specified Spreadsheet
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Set xlApp = New Excel.Application
    With xlApp
    .Visible = True
    Set xlWB = .Workbooks.Open("C:\Documents and Settings\Template.xls", , False)
    End With
    End Function

    But when I change the file type to 2007 .xlsx or .xlsm (see below), the open command fails.

    Set xlWB = .Workbooks.Open("C:\Documents and Settings\Template.xlsx", , False)


    Can anyone help?

  2. #2
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    BigMix, what was your solution on this? I have been having the same issue with opening any MS 2007 files from my Access 2007 DB, but it works just fine for MS 2003 or earlier files.

  3. #3
    Bigmix is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    11
    xlsm File for a template:

    Option Compare Database
    Option Explicit
    Sub OpenSpecific_xlFile()
    ' Late Binding (Needs no reference set)
    Dim oXL As Object
    Dim oExcel As Object
    Dim sFullPath As String
    Dim sPath As String


    ' Create a new Excel instance
    Set oXL = CreateObject("Excel.Application")


    ' Only XL 97 supports UserControl Property
    On Error Resume Next
    oXL.UserControl = True
    On Error GoTo 0


    ' Full path of excel file to open
    On Error GoTo ErrHandle
    sFullPath = CurrentProject.Path & "\Scorecard Template.xlsm"


    ' Open it
    With oXL
    .Visible = True
    .Workbooks.Open (sFullPath)
    End With


    ErrExit:
    Set oXL = Nothing
    Exit Sub

    ErrHandle:
    oXL.Visible = False
    MsgBox Err.Description
    GoTo ErrExit
    End Sub

  4. #4
    Bigmix is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    11
    Hope that helps.

    Here is the command button under Event > On Click

    Option Compare Database
    Private Sub cmdOpenExcelFIle_Click()
    ' Access form button
    Call OpenSpecific_xlFile

    End Sub
    Last edited by Bigmix; 02-14-2012 at 01:50 PM. Reason: Spelling

  5. #5
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    Thanks for the post of your solution Bigmix ... unfortunately for me, I need something that will work for all types of files, not just Excel. I'm afraid that I may need to code for each specific MS Office 2007 file type and then treat all other files with a simple Application.FollowHyperLink. Thanks again and this may be helpful to someone else who is experiencing the same issue!

  6. #6
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    Bigmix, I wanted to share with you the solution that I put in place for my database. Unfortunately, I was having issues where users couldn't open .docx or .xlsx files, so with your code above and assistance from some other threads I found, I came up with the code I posted in my original thread here. Just thought you may want to check it out. Thanks for your help.

  7. #7
    Bigmix is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    11
    Quote Originally Posted by gopherking View Post
    Bigmix, I wanted to share with you the solution that I put in place for my database. Unfortunately, I was having issues where users couldn't open .docx or .xlsx files, so with your code above and assistance from some other threads I found, I came up with the code I posted in my original thread here. Just thought you may want to check it out. Thanks for your help.
    That will come in very handy. Thank you for keeping me in mind.

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

Similar Threads

  1. to open Exported Excel File
    By waqas in forum Programming
    Replies: 3
    Last Post: 10-16-2011, 12:33 PM
  2. Open excel file in access
    By shanky365 in forum Access
    Replies: 1
    Last Post: 09-11-2011, 03:05 PM
  3. 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
  4. Replies: 0
    Last Post: 11-17-2009, 02:35 PM
  5. Open / Save as Excel File and specifiy format
    By jaykappy in forum Access
    Replies: 8
    Last Post: 03-24-2009, 03:26 PM

Tags for this Thread

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