Add reference to solidworks library in excel vba.
then you can do the solidwork programming in excel vba same as u do in solidworks vba.
At first I tried something with ShellExecute, but my skills aren't good enough to understand the solutions people bring forward (Keep on getting errors).
Rais, I'll try it your way, thanks for the reply!
This is definitly what I want, thanks.
It isn't quite working though; I'm getting the following error:
Run-time error '429':
ActiveX component can't create object
off topic, i think it's time to take a class in VBA
First of all,
I lack A LOT of knowledge in VBA (as I have none) so I might have made wrong assumptions, but:
I've got a working button .
I tried your code at first, but it didn't work. I compared it with other code I had that managed to open sw as a program. I ended up with the following code in my button:
Private Sub CommandButton1_Click()
Set swapp = CreateObject("sldworks.application")
swapp.Visible = True
swapp.OpenDoc "C:\part1.sldprt", 1
first, somehow publicly 'set swapp as object' upfront and then GetObject didn't work. This does, so i stuck with it
second, don't know why but if I don't add the swapp.Visible = True, it looks like it doesn't do anything.
I guess it still works without the line (as logicaly it should only set visibility) and windows seems somehow busy for a while. Later when I return that line of code and run it, it's immediatly done.
Anyway without it it doesn't what I want it to do, and now it does .
Thanks for your help!!
PS: I also found out that IF I want to open a drawing instead of a part, the last rule should end in ",3" instead of ",1". I presume the number at the end tells solidworks wether it's a .sldprt (1), a .sldasm (2, haven't checked this though) or a .slddrw (3, have checked this )
Message was edited by: Stijn Chapelle
I am trying to do somthing similar to you and i have no knowledge of VBA, so i think you can help me here. I got the success of launching solidworks with the help of macro in excel. Now the next step is that I want to pass some values to the global variables in solidworks from excel can you help me to get aroud it.
First of all, I have barely any knowledge of VBA myself (just started playing with it last week). I'm doing roughly the samething as you want to do. What I did was made all my dimensions that might change either global variables, or quations. Then I generate a .txt with the global variables (and equations) in it and linked them to the equations in my part. That way, when I change my .txt file, the .sldprt changes with it (after a rebuild )
Hope this helps!
Well I did the same thing I created a text file linked to my global variables and then passed some values from my excel file to the text file through a macro and the same macro runs the solidworks and rebuilds the model and give me the final model. Offcourse your thread and some other searching helped alot. And I got what I wanted to get and that is total automation of my model...a working firetruck door with variable width and height.
You can work with equations (SW global variables) directly without txt file.
Use the IEquationMgr interface (accessor - IModelDoc2::GetEquationMgr) and EquationMgr::Add2 method. Here are the example:
Application Engineer at Intercad
Tel: +61 2 9454 4444
I already thought so, but for now we like to work with the .txt file (gives us an extra step of 'control'). I might try it without in the near futur though (of maybe directly change the dimensions), so thanks for the hint!
Still having some kind of trouble...
I manage to build a correct .txt file which my .sldprt uses for (linked) equations. When I open this file with my windows explorer and rebuild everything works fine.
When I open it using the button with the above code (see 'correct' answer) and I rebuild my part; the global variables and equations all turn into ??? with a yellow triangular error sign that says: "Unable to compute value. Invalid entry."
However, when I save the part, close SW and double-click on the part in the explorer, it all works again.
After I save this, and use my button again, the equations turn into errors again.
his tells me the error is in the way I open the document.
At the moment I use:
sldworks.application.OpenDo path, 1 (for part, 3 for drawing). If I use OpenDoc6 instead of OpenDoc it doesn't open my part anymore.
Anyone here who can help?
I am having a similar problem with my global variables having the yellow triangular sign that says: "Unable to compute value. Invalid entry."
After running my code, I get that symbol next to every global variable, even ones that I manually add. So to recap, its almost like the part and assembly are corrupted as it does not allow me to add new global variables.
Did you ever find out what is causing this issue and what the workaround is?