Hi,
You need to set a reference to Microsoft Excel Object Library x.x in the
VB-editor via the command Tools | Reference... and then add the following code inte a standardmodule:
Code:
Option Explicit
Sub Control_XL()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim bXLRunning As Boolean
Dim stMainWbook As String
stMainWbook = "C:\Test.xls"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err Then
bXLRunning = True
Set xlApp = New Excel.Application
End If
On Error GoTo Err_Handler
Set xlBook = xlApp.Workbooks.Open(FileName:=stMainWbook)
If bXLRunning Then
xlApp.Quit
End If
Set xlBook = Nothing
Set xlApp = Nothing
Exit Sub
Err_Handler:
MsgBox stMainWbook & " caused a problem. " & Err.Description, vbCritical, _
"Error: " & Err.Number
If bXLRunning Then
xlApp.Quit
End If
End Sub
Pleas run above code and let us now the outcome of it. If OK we then take the next step
Kind regards,
Dennis