Open an excel workbook from a solidworks macro

Hello, I can't command the opening of an excel file from a solidworks macro.

The macro runs normally without error but the file does not open.

A solution?

To test the command I try to run it apart just like this:

Sub ouverture_excel()

Workbooks.Open ("chemin du fichier")

End Sub

 

On excel it works but not on solidworks, yet the macro runs.

Have you put a reference to Excel?

Yes, I have enabled the Microsoft Excel 15.0 Object Library reference

If that's the question of course

And it's super weird because when I open it manually afterwards, it opens it in read-only mode because it's opened by the user: my name

Basically, I crash excel I think...

Hello

I guess you launch Excel with a CreateObject but do you make it visible after the creation of the object?

Dim oXL As Excel.Application
Dim oWB As Workbook

'Start excel and get application
Set oXL = CreateObject("Excel.application")
oXL.Visible = True
Opening the binder
Set oWB = oXL.Workbooks.Open(MyExcelFile)

Before trying this code, manually kills any Excel processes that might still be open...

Kind regards

2 Likes

It works, thank you very much you manage!

1 Like