Share via

TransferSpreadsheet without specifying a filename to export to

Anonymous
2020-01-22T18:37:46+00:00

I just want it to open in Excel without a file name:

dim strQry as string

strQry = "qryTest"

DoCmd.TransferSpreadsheet acExport, , strQry, , True

This is giving me an error: The action or method requires a filename argument. 

But DoCmd.TransferSpreadsheet method says filename is optional.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. Anonymous
    2020-01-22T21:47:29+00:00

    Hi Lonely,

    As Hans said, you will need a file name/path but you could also add the filename without a prompt using something like:

    Dim strExpDirectory As String

    Dim strfullname As String

    Dim strPath As String

    Dim strQry As String

    strQry = "qrytest"

    strExpDirectory = Application.CurrentProject.Path & ""

    strfullname = strExpDirectory & Format(Date, "yyyy-mm-dd")

    DoCmd.TransferSpreadsheet acExport, , strQry, strfullname, True

    This will save the fie to the same directory as your access database with the file name as today's date.

    If you want to also open the spreadsheet once it is exported then you could use:

    Dim strExpDirectory As String

    Dim strfullname As String

    Dim strPath As String

    Dim xlApp As Object

    Dim strQry As String

    strQry = "qrytest"

    strExpDirectory = Application.CurrentProject.Path & ""

    strfullname = strExpDirectory & Format(Date, "yyyy-mm-dd")

    DoCmd.TransferSpreadsheet acExport, , strQry, strfullname, True

    Set xlApp = CreateObject("Excel.Application")

            xlApp.Workbooks.Open (strfullname)

            xlApp.Visible = True

    I've used today's date as the file name but you could just have something generic

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. HansV 462.6K Reputation points MVP Volunteer Moderator
    2020-01-22T19:45:48+00:00

    Sadly, the help is incorrect: the FileName argument is required. You might use the InputBox function to prompt the user for a filename.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful