Results 1 to 6 of 6
  1. #1
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131

    Opening Excel FIle Created in Access after creation

    I am using the following command to open Excel and it opens and then closes, not sure what code I should be using
    Private Sub Command5_Click()
    Dim xlApp As Excel.Application

    Set xlApp = CreateObject("Excel.Application")

    xlApp.Visible = True

    xlApp.Workbooks.Open "J:\sales\CleanedData" & "DataAlert_" & Format(Date, "yyyyMMdd") & ".xlsx", True, False
    Debug.Print xlApp.Version
    Set xlApp = Nothing
    End Sub


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you can use all that to open excel and control to modify the sheets.
    But if you just want to open it for the user,
    Paste this code into a module, and it will open ANY file in its native application.

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


    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
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Application.FollowHyperlink filename

  4. #4
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    Do I need all that code to open the file in Excel?

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Or just the one line.

  6. #6
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    When I enter the code

    OpenNativeApp "J:\DataAlert\CleanedData" & "BD_DataAlert_" & Format(Date, "yyyyMMdd")"

    It does not recognize the OpeNativeApp command?

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

Similar Threads

  1. Replies: 14
    Last Post: 05-24-2017, 02:22 PM
  2. Import to Access from Excel File created by ASP Page
    By tssrshot in forum Import/Export Data
    Replies: 3
    Last Post: 11-29-2012, 03:52 PM
  3. Replies: 1
    Last Post: 06-10-2012, 03:41 PM
  4. Replies: 6
    Last Post: 02-24-2012, 06:09 AM
  5. VBA Opening Excel File and Placing Data in Cells
    By BobTHG in forum Programming
    Replies: 0
    Last Post: 01-13-2008, 03:01 PM

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