几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 09:57 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】open sw part using excel vba

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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】creating a reference poin on a surface yang686526 SolidWorks二次开发 0 2009-04-12 08:36 PM
【转帖】draw shaft using visual basic application yang686526 SolidWorks二次开发 0 2009-04-12 06:01 PM


所有的时间均为北京时间。 现在的时间是 08:38 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多