|
open sw part using excel vba
i wonder if you have a code to open a sw part (c:\test.sldprt) using excel vba.
thanks in advance.
maperalia
this should do what you are after.
option explicit
public swapp as sldworks.sldworks
public part as sldworks.modeldoc2
public sub activatesolidworks()
dim boolstatus as boolean
dim returnvalue as long
msgbox ("now creating a sw session - or attaching to existing session")
on error resume next
'activate solidworks
set swapp = getobject(, "sldworks.application")
'if solidworks is not started then start it
if err.number <> 0 then
set swapp = createobject("sldworks.application")
end if
set part = swapp.activedoc
'make solidworks application visible
swapp.visible = true
swapp.usercontrol = true
performswoperations
end sub
public sub performswoperations()
dim fileerror as long
dim filewarning as long
set part = swapp.opendoc("c:\test.sldprt", swdocpart)
end sub
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
edited: 12/12/2008 at 01:07 pm by ben guenther
oh and make sure to have ;
solidworks 2008 constance type library and sldworks 2008 type library
added in or it will not work.
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
ben;
thanks for the code.
when i assign the macro button to "activatesolidworks". however, when i run it i gor the windows mesage "now creating a sw session - or attaching to existing session" i click ok and then stops.
could you please tell me what i am missing?
thanks.
maperalia
here try this:
option explicit
public swapp as sldworks.sldworks
public part as sldworks.modeldoc2
public sub activatesolidworks()
dim fileerror as long
dim filewarning as long
msgbox ("now creating a sw session - or attaching to existing session")
on error resume next
'activate solidworks
set swapp = getobject(, "sldworks.application")
'if solidworks is not started then start it
if err.number <> 0 then
set swapp = createobject("sldworks.application")
end if
set part = swapp.activedoc
'make solidworks application visible
swapp.visible = true
swapp.usercontrol = true
set part = swapp.opendoc("c:\test.sldprt", swdocpart)
end sub
first example has two subs and it was looking at the wrong one.
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
edited: 12/12/2008 at 03:34 pm by ben guenther
ben;
thanks for the update code. however, it is working the same way of the last one. after. when i run it i got the windows message "now creating a sw session - or attaching to existing session" i click ok and then stops.
could you please tell me if i did something wrong?
kind regards.
maperalia
so it is not working in anyway at all ?
did you make sure that the part is called exactly what you have in the code ?
is the path exactly what is in the code ?
that message box is coded to come up if you don't want it to show, just put a quotation mark in front of msgbox ("now creating a sw session - or attaching to existing session") or delete that line then it will not come show up.
if you are not getting an error message when running the code then it's a good chance that the part name or the path is wrong in the code.
it works fine for me.
but let me know how you make out.
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
edited: 12/12/2008 at 04:28 pm by ben guenther
ben;
i noticed that did not type the code as you sent me. now i copied and pasted it and is working perfectly!!!!!!!.
thanks very much for your help. i really appreciate your helping me in this matter....
kind regards.
maperalia
quick |
|