| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 721 人关注过本帖
标题:vb与ms publisher打印
只看楼主 加入收藏
houyoung
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-10-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:6 
vb与ms publisher打印
我需要用excel来控制打印对应ms publihser文档,假设:文档名为"c:\1009.pub",该文档已经设置过自定义页面,如19cm*6.6cm,打印机中有自定义纸型6.6cm*19cm,名字叫200M
我的vba代码如下:
Sub Fprint()
Dim oAdd As Object
Dim apppub As Object '
Dim pub As Publisher.Application
Dim pubInstalledPrinters As Publisher.InstalledPrinters
Dim pubApplication As Publisher.Application
Dim pubPrinter As Publisher.Printer
Dim FileName As String
FileName = "c:\1009.pub"
Application.EnableEvents = False

Set apppub = CreateObject("Publisher.Application")
On Error GoTo ErrorHandler
apppub.Open FileName, False, True, pbDoNotSaveChanges

Set pubApplication = ActiveDocument.Application'''可能报错的位置
Set pubInstalledPrinters = pubApplication.InstalledPrinters

apppub.ActiveWindow.Visible = True
For Each pubPrinter In pubInstalledPrinters
If pubPrinter.IsActivePrinter Then
 
ActiveDocument.PageSetup.PageHeight = Publisher.CentimetersToPoints(6.6)
ActiveDocument.PageSetup.PageWidth = Publisher.CentimetersToPoints(19)
pubPrinter.PaperHeight = Publisher.CentimetersToPoints(19)
pubPrinter.PaperWidth = Publisher.CentimetersToPoints(6.6)
pubPrinter.PaperOrientation = pbOrientationLandscape

ActiveDocument.PrintOutEx FROM:=1, To:=1, COPIES:=1
End If
Next

 apppub.Quit
   Set apppub = Nothing
   Exit Sub

ErrorHandler:
   apppub.Quit
   Set apppub = Nothing

end sub
结果有2个问题:1、打印纸型不对,尺寸是A4,且文档被打印在纸张最中央;2、如果打印一次该文档后,不关闭excel,直接再打印一次,462错误,远程服务器不存在或不可用,调试就落在标记可能错误的地方那个,请大家给与解答。
搜索更多相关主题的帖子: Object Create 打印机 excel 
2013-10-05 11:22
houyoung
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-10-5
收藏
得分:0 
有偿
2013-10-05 12:55
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:10 
Set pubApplication = apppub.ActiveDocument.Application ' 试试吧。
2013-10-05 17:48
houyoung
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-10-5
收藏
得分:0 
谢谢,462的错误是windows自身资源不能很快释放造成的,如何能加速它释放资源呢?
2013-10-05 23:11
houyoung
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-10-5
收藏
得分:0 
该问题是有偿的,不是20分的问题
2013-10-05 23:12
houyoung
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-10-5
收藏
得分:0 
期待高手
2013-10-06 10:12
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:10 
以下是引用houyoung在2013-10-5 11:22:47的发言:

我需要用excel来控制打印对应ms publihser文档,假设:文档名为"c:\1009.pub",该文档已经设置过自定义页面,如19cm*6.6cm,打印机中有自定义纸型6.6cm*19cm,名字叫200M
我的vba代码如下:
Sub Fprint()
Dim oAdd As Object
Dim apppub As Object '
Dim pub As Publisher.Application
Dim pubInstalledPrinters As Publisher.InstalledPrinters
Dim pubApplication As Publisher.Application
Dim pubPrinter As Publisher.Printer
Dim FileName As String
FileName = "c:\1009.pub"
Application.EnableEvents = False

Set apppub = CreateObject("Publisher.Application")
On Error GoTo ErrorHandler
apppub.Open FileName, False, True, pbDoNotSaveChanges

Set pubApplication = ActiveDocument.Application'''可能报错的位置
Set pubInstalledPrinters = pubApplication.InstalledPrinters

apppub.ActiveWindow.Visible = True
For Each pubPrinter In pubInstalledPrinters
If pubPrinter.IsActivePrinter Then
 
ActiveDocument.PageSetup.PageHeight = Publisher.CentimetersToPoints(6.6)
ActiveDocument.PageSetup.PageWidth = Publisher.CentimetersToPoints(19)
pubPrinter.PaperHeight = Publisher.CentimetersToPoints(19)
pubPrinter.PaperWidth = Publisher.CentimetersToPoints(6.6)
pubPrinter.PaperOrientation = pbOrientationLandscape

ActiveDocument.PrintOutEx FROM:=1, To:=1, COPIES:=1
End If
Next

 apppub.Quit
   Set apppub = Nothing
   Exit Sub

ErrorHandler:
   apppub.Quit
   Set apppub = Nothing

end sub
结果有2个问题:1、打印纸型不对,尺寸是A4,且文档被打印在纸张最中央;2、如果打印一次该文档后,不关闭excel,直接再打印一次,462错误,远程服务器不存在或不可用,调试就落在标记可能错误的地方那个,请大家给与解答。

以下是引用houyoung在2013-10-5 23:11:28的发言:

谢谢,462的错误是windows自身资源不能很快释放造成的,如何能加速它释放资源呢?


在代码中设置纸张类型。阻止用户太快再次打印比vb加速windows释放资源可能更好。

[ 本帖最后由 Artless 于 2013-10-6 11:51 编辑 ]

无知
2013-10-06 11:49
快速回复:vb与ms publisher打印
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012891 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved