Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Dec 2001
    Location
    Rickmansworth, Hertfordshire, United Kingdom
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access 2003: Command line error when starting Excel

    I have a form containing a button that runs a macro which is supposed to open an Excel file. The command line reads 'C:\Program Files\Microsoft Office\Office11\excel.exe C:\Documents and Settings\admin\Desktop\subscriptions.xls'. When the macro runs, Excel opens but with an error message:'C:Documents.xls could not be found'. Why is the command line entry being truncated?
    Last edited by RetiredGeek; 2013-08-21 at 21:01.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Roger,

    I think you're running into a problem with spaces in the file name.
    Try Replacing the filename with C:\Docum~1\admin\Desktop\subscriptions.xls.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Star Lounger
    Join Date
    Dec 2009
    Location
    Findlay, Ohio
    Posts
    57
    Thanks
    4
    Thanked 6 Times in 6 Posts
    I tried a macro using runapplication with:
    "C:\Program Files (x86)\Microsoft Office\Office14\excel.exe" "C:\Users\fred\Documents\a folder with spaces\test.xlsx"
    and it worked using Office 2010. I do not have Office 2003 to test with.

  4. #4
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,721
    Thanks
    146
    Thanked 156 Times in 149 Posts
    I've used similarly with Office 2003 and it works as well. You just need the double quotes around the arguments though they aren't necessary when there are no spaces (but it's good practice to do this anyway).

  5. #5
    Star Lounger
    Join Date
    Dec 2001
    Location
    Rickmansworth, Hertfordshire, United Kingdom
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    RG's suggestion didn't work, neither did the other two suggestions. However, I've got there after moving the xls file from the desktop to a user folder and putting double quotes around just the second part of the argument, ie, C:\Program Files\Microsoft Office\Office11\excel.exe "D:\IOFS office\RogerTrigg\subscriptions.xls".
    Curiously when I tried just opening Excel with "C:\Program Files\Microsoft Office\Office11\excel.exe" Excel wouldn't open; take away the double quotes and it did.
    Thanks, all for your help.

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Roger,

    Don't know exactly how you were trying to load excel but here's code that I've tested and it works.
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Command0_Click()
    
       Dim objExcel As Object
       Dim objWkBk  As Object
       
       Set objExcel = CreateObject("Excel.Application")
       
       Set objWkBk = objExcel.Workbooks.Open("G:\BEKDocs\Excel\Test\Audit Sample.xlsx", , False)
       objExcel.Visible = True
       
       MsgBox "Press OK to dismiss this msg and" & vbCrLf & _
              "Close the workbook and Excel.", _
              vbOKOnly + vbInformation, "File Opened: " & objWkBk.Name
       
       objWkBk.Close (False)
       Set objExcel = Nothing
       
    End Sub
    Notes:

    • The example uses Late Binding so no references have to be set and it is Office version independent.
    • Also if you attempt to open a .xls file in 2007/10 it will open Read Only (don't know why but I couldn't get it to open R/W) but xlsx files will open R/W as requested by the False parameter in the Open command. I tried this both with the Excel directory in Trusted Locations and w/o it there.

    HTH
    Last edited by RetiredGeek; 2013-08-22 at 20:07.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •