Alan McGowan
Senior Member
- Outlook version
- Outlook 2013 64 bit
- Email Account
- Exchange Server
I am trying to open an Excel spreadsheet from within Outlook using the code below. It works perfectly if Excel is already running. If Excel is not already open it seems to open Excel (as it appears in task manager) but doesn't open the spreadsheet. Any ideas?
Dim xl As Object
Dim xls As Object
Dim strxls As String
Dim intSection As Integer
Dim intTries As Integer
Dim strFullPathAndFileName As String
' Set full path and filename
strFullPathAndFileName = "C:\filemail\fm_settings.xlsm"
intSection = 1 ''attempting GetObject...
On Error Resume Next
' Try to refer to running instance of Excel
Set xl = GetObject(, "Excel.Application")
xl.Visible = True
' If Excel wasn't running...
If xl Is Nothing Then
' start Excel
Set xl = CreateObject("Excel.Application")
xl.Visible = True
If xl Is Nothing Then
MsgBox "Can't start Excel!", vbExclamation
Exit Sub
End If
End If
On Error GoTo 0
intSection = 0 ''resume normal error handling
' Open text file
Set xls = xl.Workbooks.Open(strFullPathAndFileName)
Set xl = Nothing
Dim xl As Object
Dim xls As Object
Dim strxls As String
Dim intSection As Integer
Dim intTries As Integer
Dim strFullPathAndFileName As String
' Set full path and filename
strFullPathAndFileName = "C:\filemail\fm_settings.xlsm"
intSection = 1 ''attempting GetObject...
On Error Resume Next
' Try to refer to running instance of Excel
Set xl = GetObject(, "Excel.Application")
xl.Visible = True
' If Excel wasn't running...
If xl Is Nothing Then
' start Excel
Set xl = CreateObject("Excel.Application")
xl.Visible = True
If xl Is Nothing Then
MsgBox "Can't start Excel!", vbExclamation
Exit Sub
End If
End If
On Error GoTo 0
intSection = 0 ''resume normal error handling
' Open text file
Set xls = xl.Workbooks.Open(strFullPathAndFileName)
Set xl = Nothing