In the references, set a reference to Excel
Then use the following code:
On Error Resume Next
Set xlsObject = GetObject(, "Excel.Application")
Err.Clear
If xlsObject Is Nothing Then
Set xlsObject = CreateObject("Excel.Application")
End If
On Error GoTo Errorhandler
Set xlsWorkbook = xlsObject.Workbooks.Add()
This will look to find an instance of Excel and if there is one use it. If
there is not, an error is generated (hence the On Error Resume Next) and
then a new instance of Excel is created.
Dave
"R.W." <(E-Mail Removed)> wrote in message
news:1f29501c45761$83960df0$(E-Mail Removed)...
> In one of my projects I create an Excel Workbook and add
> a new Excel workbook with this code:
>
> Set xlsObject = CreateObject("Excel.Application")
> Set xlsWorkbook = xlsObject.Workbooks.Add()
>
> But when the user previously has opened MS Excel himself,
> this causes problems. So I need a methode to check if the
> user has opened Excel already. If not I can use previous
> code otherwise I need a way to assign the open Excel
> application to the variable xlsObject.
>
> All positive suggestions welcome, thanks
>
> R.W.
|