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错误,远程服务器不存在或不可用,调试就落在标记可能错误的地方那个,请大家给与解答。