View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
JHB JHB is offline
external usenet poster
 
Posts: 30
Default Opening excel 2010 spreadsheet from Access

On Feb 25, 4:59*pm, GS wrote:
Here's a reusable function that will work with whatever version of
Excel is the default...

In a standard module:

Public appXL As Object
Const sXLS_TO_OPEN$ = "C:\TASC\apps\TASCSpredGen.xls" '//edit to suit

Function OpenExcelFile(FileName$) As Boolean
* Dim wkb As Object

* On Error GoTo errexit
* Set appXL = CreateObject("Excel.Application")
* If Not appXL Is Nothing Then Set wkb = appXL.Workbooks.Open(FileName)

errexit:
* OpenExcelFile = (Not wkb Is Nothing)
* Set wkb = Nothing
End Function 'OpenExcelFile

In the procedure that currently opens the file, replace that code
with...

* If OpenExcelFile(sXLS_TO_OPEN) Then
* * appXL.Visible = True: appXL.UserControl = True
* Else
* * appXL.Quit: Call Notify_FileOpenFailure(sXLS_TO_OPEN)
* End If
* Set appXL = Nothing '//release it from memory

..so if the file opened successfully you can turn the Excel instance
over to the user by making it visible (otherwise it remains hidden),
and allowing user control. If unsuccessful you could notify the user
there was a problem opening the file...

Sub Notify_FileOpenFailure()
* MsgBox "There was a problem opening " & sXLFileToOpen & "!"
End Sub

--
Garry

Free usenet access athttp://www.eternal-september.org
Classic VB Users Regroup!
* comp.lang.basic.visual.misc
* microsoft.public.vb.general.discussion


Thanks very much.. I will try that -- appreciate it!

John