View Single Post
  #4   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 26, 6:55*am, JHB wrote:
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


There seems to be a problem here.

I am getting a "Compile error -- by ref type missmatch" when the
standard module trys to interpret sXLFileToOpen. I know I have the
right path and file name in the following setup:
Option Compare Database
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


, and am uncertain what the solution is.
John