Results 1 to 5 of 5
  1. #1
    JHCorley is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2016
    Posts
    3

    Open table/query as Excel file via TransferSpreadsheet

    I used to be able to use TransferSpreadsheet to export data to Excel, not to a file.

    In other words, the data would pop up in Excel without the user having to open a saved file.

    Is this possible with MS Office Access 2007?

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    an excel sheet IS a file.
    use:

    vFile = "C:\filder\file.xls"
    docmd.transferspreadsheet vFile
    openNativeApp vFile 'this code is below


    Paste this code into a module, and it will open ANY file in its native application.

    usage: OpenNativeApp "c:\folder\file.pdf"
    will open it in acrobat
    and
    OpenNativeApp ME.txtBox
    will open the doc in Word if the item in txtBox is C:\myfile.doc

    if its just a file path, it will open in file explorer.

    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub

  3. #3
    JHCorley is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2016
    Posts
    3
    I thought there was a parameter that could be used with TransferSpreadsheet to do this.

    I assume your code is opening the newly saved file.

    In any case, I copied your code and it doesn't recognize StartDoc().

    Can I get the code for this as well?

    Thanks.

  4. #4
    JHCorley is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2016
    Posts
    3
    I was able to open the saved file using Shell() but it opens a new instance of Excel each time.

    Does StartDoc() do this as well?

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    First you export the data into an Excel file with TransferSpreadsheet. After that you open the file with : Application.Followhyperlink nameoffile

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

Similar Threads

  1. Replies: 8
    Last Post: 08-29-2016, 12:17 PM
  2. Replies: 5
    Last Post: 05-25-2016, 12:43 PM
  3. Replies: 11
    Last Post: 03-02-2016, 11:01 AM
  4. Importing Excel file: ADODB, DAO or DoCmd.TransferSpreadsheet
    By Monterey_Manzer in forum Import/Export Data
    Replies: 3
    Last Post: 08-13-2013, 11:34 AM
  5. Replies: 2
    Last Post: 02-27-2010, 06:53 AM

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