Open an excel sheet

  • Thread starter Thread starter Ian P
  • Start date Start date
I

Ian P

I am trying to open an excel document from Access. I am
using a macro, with the Runapp command, but I can only get
it to open excel with a new (blank) document, but I want
to open an existing one. I have tried entering the direct
file path into the command line, but it wont open.

e.g. c:\documents\excel sheets\document tempate.xls

anyone have any ideas?

Thanks
Ian
 
Ian:

This can only be done use Visual Basic rather than a macro. Of course once
you write the VB function you can call it from a macro:

Function OpenWorkbook(strWorkbookPath As String) As Boolean
Dim objXL As Object
Dim objBook As Object

On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
If Err <> 0 Then _
Set objXL = CreateObject("Excel.Application")
On Error GoTo ErrHandler
objXL.Visible = True
Set objBook = objXL.Workbooks.Open(strWorkbookPath)
OpenWorkbook = True
ExitProc:
Exit Function
ErrHandler:
OpenWorkbook = False
Resume ExitProc
End Function
 
Back
Top