几何尺寸与公差论坛

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

【转帖】list all network printers

[复制链接]
发表于 2009-4-13 12:31:13 | 显示全部楼层 |阅读模式
list all network printers
i used this loop to list all network printes
dim x as printer
for each x in printers
cboprinters.additem x.devicename
next
but it doesn't seem working.
any idea?
thx, chris
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
chris,
what's the error? if you add a watch on the printers object, do you see your printers?
i have used the for each x in printer method and also enumprinters (search msdn for enumprinters). both work fine for me, but enumprinters method takes more code.
mike
i got the error: user-defined type not defined
see the att. image for ref
thx, chris
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
ok, you are right to look under references. i used visual basic 6.0 with the printers object. with some digging, the reference it needs is "visual basic objects and procedures" (vb6.olb). this is not a listed reference in solidworks vba. that did not stop me though and i used the browse button to manually select vb6.olb. the dim statement then reconized the object, but when it got to the for each x in printer statement, it crashed solidworks.
so the bottom line is, it does not look like you can use the printers object in solidworks vba. vb6 works great with printer object though, so if you have it, that's the way to go. if you don't have vb6, i would suggest trying the enumprinters method. it's a bit involved, but it does work inside solidworks vba.
-mb
i do have vb6
how to load it into the sw vba?
thx, chris
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
paste the following code into a new vb6 project and set your references as shown in the attachment. i'm not sure what you are asking about "load it into the sw vba", but the last couple lines in this example gets the solidworks object and the modeldoc object from vb6.
-mb
private sub main()
dim x as printer
dim swapp as sldworks.sldworks
dim swmodeldoc as modeldoc2
'printers
for each x in printers
if x.devicename = "pdf995" then
set printer = x
printer.papersize = 158
exit for
end if
next
'linking to solidworks
set swapp = createobject("sldworks.application")
set swmodeldoc = swapp.activedoc
end sub
click for full image
michael,
i never have problem with vb6 - so this code works fine
dim x as printer
for each x in printers
cboprinters.additem x.devicename
next
however, when i add them to solidworks vba, i got an error
thx, chris
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
chris,
as far as i can tell it does not look like you can use the "printers" object in solidworks vba. (in a prior post i said i had attempted to add the vb6 reference (vb6.olb) to solidworks vba, but it crashes solidworks). i would suggest using the enumprinters method.
-mike
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 14:34 , Processed in 0.034826 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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