export to and open excel without specifying directory

  • Thread starter Thread starter Mike Brearley
  • Start date Start date
M

Mike Brearley

Currently I am specifying the exact path to the excel file in both vb code
for buttons and in the 'Run App'

The macro for run app:
excel.exe "c:\folder\file.xls"

In the VB code, I'm exporting data out to the excel file:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "MyQuery",
"c:\folder\file.xls", True

I'd like to be able to specify the filename and have the directory use the
current directory that the database is running in. Please help.

Thanks...
 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "MyQuery",
CurrentProject.Path & "\" & "file.xls", True
 
Thank you Doug!! You pointed me in the right direction and I now have that
part working.

A couple of things to note:

If there are spaces in the folder structure, be sure to put in quotes like
this:
, """" & CurrentProject.Path & "\" & "file.xls" & """", True

I found to open the excel file, I can use this:
Shell "excel.exe " & """" & CurrentProject.Path & "\Machine_OEE_Chart.XLS" &
"""", vbNormalFocus

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top