Stuart McLachlan
stuart at lexacorp.com.pg
Sat May 26 21:13:36 CDT 2012
You need to quote the program path because it has spaces in it. Application.RunQQ( "C:\Program Files (x86)\Microsoft Office\Office11\Excel.exe") & " " & strFile Alternatively, use ShellExecute() and you don't need to worry about the path to Excel on the machine you are running on. Public Declare Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long ... ShellExecute Application.hWndAccessApp, "Open", strFile, "", "", vbNormalFocus -- Stuart On 26 May 2012 at 21:08, Arthur Fuller wrote: > Last week I posted a question about how to do this. In the interim I've > worked most of it out. I can create the XLS file, and export the data to > it, but can't make the last step work. Once the file has been created and > written to, I want Excel to open and open the file too. I've tried various > syntaxes, including: > > <vba> > Public Sub RunExcel(strFile As String) > Application.Run "C:\Program Files (x86)\Microsoft > Office\Office11\Excel.exe " & strFile > Application.Run "C:\Program Files (x86)\Microsoft > Office\Office11\Excel.exe " & Q(strFile) > Application.Run "C:\Program Files (x86)\Microsoft > Office\Office11\Excel.exe " & QQ(strFile) > End Sub > > Public Function Q(str As String) > Q = Chr(39) & str & Chr(39) > End Function > > Public Function QQ(str As String) > QQ = Chr(34) & str & Chr(34) > End Function > </vba> > > (Incidentally, I included the two utility functions because they are > enormously convenient, so feel free to copy them and use them. They're good > for wrapping strings that might contain single or double quotes, for > example.) > > All three calls fail with the message, the only difference being whether > the filename is wrapped in quotes or not. > Microsoft Access can't find the procedure 'C:\Program Files > (x86)\Microsoft Office\Office11\Excel.exe > "c:\temp\Customers.xls".' > > Does anyone know how to accomplish this? > TIA, > -- > Arthur > Cell: 647.710.1314 > > Prediction is difficult, especially of the future. > -- Niels Bohr > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > -- Stuart McLachlan Ph: +675 340 4392 Mob: +675 7100 2028 Web: http://www.lexacorp.com.pg