Opening the Excel file using VBA (1 Viewer)

manoj.mcans

Registered User.
Local time
Today, 03:57
Joined
Sep 1, 2008
Messages
18
Hi,
I am trying to open the excel file using VBA in MsAccess using below code, its execute fine and but didnot open the excel file
Can any one help me where i am missing , that would be great help.

---On Btn Click event------------
Private Sub Command0_Click()
Call ExcelInstance
End Sub

-----Check the excel file is runing or not------
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0)
Set xlApp = Nothing
Err.Clear
End Function

------Opening the excel file-------------------------
Public Sub ExcelInstance()
Dim xlApp As Excel.Application
Dim ExcelRunning As Boolean
ExcelRunning = IsExcelRunning()
If ExcelRunning Then
Set xlApp = GetObject(, "Excel.Application")
Else
Set xlApp = CreateObject("Excel.Application")
End If
xlApp.Workbooks.Open "Path of File with folder name", True, False
If Not ExcelRunning Then xlApp.Quit
Set xlApp = Nothing
End Sub

:)
 

ajetrumpet

Banned
Local time
Yesterday, 22:57
Joined
Jun 22, 2007
Messages
5,638
its execute fine and but didnot open the excel file

---On Btn Click event------------
Private Sub Command0_Click()
Call ExcelInstance
End Sub

-----Check the excel file is runing or not------
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0) <---- what are you doing here?
Set xlApp = Nothing
Err.Clear
End Function

------Opening the excel file-------------------------
Public Sub ExcelInstance()
Dim xlApp As Excel.Application
Dim ExcelRunning As Boolean
ExcelRunning = IsExcelRunning() <---- do you get the boolean that you need here!?
If ExcelRunning Then <---- don't you need a "= TRUE" portion here?
Set xlApp = GetObject(, "Excel.Application")
Else
Set xlApp = CreateObject("Excel.Application")
End If
xlApp.Workbooks.Open "Path of File with folder name", True, False
If Not ExcelRunning Then xlApp.Quit
Set xlApp = Nothing
End Sub

:)
maybe a shorter version of this that would open the book would be this (in ONE function):
Code:
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")

xlApp.visible = TRUE

xlApp.Workbooks.Open "Path of File with folder name", True, False

set xlApp = NOTHING
 

manoj.mcans

Registered User.
Local time
Today, 03:57
Joined
Sep 1, 2008
Messages
18
Thanks

Its working fine
 

lpopa

New member
Local time
Yesterday, 20:57
Joined
Feb 4, 2014
Messages
7
maybe a shorter version of this that would open the book would be this (in ONE function):
Code:
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = TRUE
xlApp.Workbooks.Open "Path of File with folder name", True, False
set xlApp = NOTHING

Using this code was giving me an error in Access 2013. But changing the below made it work perfectly. Thank you!

Code:
[B]Dim xlApp As [COLOR="Red"]Excel.Application[/COLOR] [/B]
Change to:
[B]Dim xlApp As [COLOR="Blue"]Object [/COLOR][/B]
 

Rx_

Nothing In Moderation
Local time
Yesterday, 21:57
Joined
Oct 22, 2009
Messages
2,803
I am looking at moving to Access 2013 on our Citrix Servers in a couple of months.
Just got to ask: On your Access 2013 Tools Reference in the Code module
Did you set the Reference to Excel 2013?
Thanks
 

lpopa

New member
Local time
Yesterday, 20:57
Joined
Feb 4, 2014
Messages
7
Here's a screenshot of all the references I have checked off.

Why do you ask? What does that impact?
 

Attachments

  • references.PNG
    references.PNG
    23.4 KB · Views: 2,849

Users who are viewing this thread

Top Bottom