Forum Discussion

MichaelB200's avatar
MichaelB200
Copper Contributor
Oct 30, 2024
Solved

Opening Excel from an Access Command Button

I am trying to open the MS Excel Application from a Command Button in Access.

 

the Code I am using is

Private Sub MicrosoftExcel_Click()

     Dim App As Object
     Set App = CreateObject("excel.Application")
     App.Visible = True

End Sub

 

When clicking on the Command Button, I can see Excel start to run in the taskbar, but it immediately closes.  I have no problem starting Word using


Private Sub MicrosoftWord_Click()

     Dim App As Object
     Set App = CreateObject("Word.Application")
     App.Visible = True
End Sub

 

Anyone have any suggestions?

 

  • MichaelB200 , you Add a Workbook so it will stay open:

     

    Private Sub MicrosoftExcel_Click()
    
         Dim App As Object
         Set App = CreateObject("excel.Application")
         
         'arnelgp
         App.Workbooks.Add
         
         App.Visible = True
    
    End Sub
  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    MichaelB200 , you Add a Workbook so it will stay open:

     

    Private Sub MicrosoftExcel_Click()
    
         Dim App As Object
         Set App = CreateObject("excel.Application")
         
         'arnelgp
         App.Workbooks.Add
         
         App.Visible = True
    
    End Sub
      • arnel_gp's avatar
        arnel_gp
        Steel Contributor

        MichaelB200  remove the adding of workbook, but instead Open the existing workbook:

         

        ..
        ..
        App.Workbooks.Open "thePath + filename of your excel file here"
        ..
        ..

Resources