几何尺寸与公差论坛

 找回密码
 注册
查看: 576|回复: 0

【转帖】open sw part using excel vba

[复制链接]
发表于 2009-4-12 21:57:33 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 14:45 , Processed in 0.037165 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表