通过vb.net在Word 2010中选择打印机纸盘 [英] Selecting printer Trays in Word 2010 via vb.net

查看:268
本文介绍了通过vb.net在Word 2010中选择打印机纸盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个用VB.net编写的用于批量打印作业的应用程序.

作为该应用程序的一部分,用户选择两个打印机托盘用于将批次打印到(一个普通纸,另一种颜色用于封面和批次分隔器)

在将系统从带有Office 2000的Windows XP升级到Windows 7和Office 2010之前,我一直在进行此工作.现在无法识别所选的纸盘,并且会引发错误.
我在这里和其他论坛上都看过类似的帖子,但是他们希望专注于使用一些默认单词托盘(wdPrinterDefaultBin等),但是我需要让用户选择他们想要使用的任何托盘.

我不想遍历大楼中的每台打印机,也不必将托盘映射到单词值,因为我不想每次我们拥有一台新打印机时都重写应用程序.

这是代码:

Hi All,
I have an application written in VB.net for batch print jobs.

As part of the application, the user selects two printer trays to use to print the batch to (one plain paper the other coloured for coversheets and batch seperators)

I had this working until we upgraded our systems from Windows XP with Office 2000 to Windows 7 and Office 2010. Now the selected trays are not being recognised and an error is thrown.

I''ve looked at similar posts on here and other forums but they seam to concentrate on using some word default trays (wdPrinterDefaultBin etc) however I need to be able to let the user pick whatever tray they wish to use.

I don''t want to have to go through every printer in the building and map the trays to the word values either as I don''t want to rewrite the app everytime we''ve a new printer.

Here is the code:

sub PopulatePrinterTray (byref Printer as String)
'gets printer trays for selected printer and then populates some comboboxes
Dim pkSource As Printing.PaperSource
Dim printDoc As New Printing.PrintDocument

'Clear the comboboxes
 cbDocTray.Items.Clear()
 cbRedTray.Items.Clear()
'take printer paper sources i.e. trays
 printDoc.PrinterSettings.PrinterName = Printer
For Each pkSource In printDoc.PrinterSettings.PaperSources
  'dataitem custom class holds a ID and a string (displays string)
   cbDocTray.Items.Add(New DataItem(pkSource.RawKind, pkSource.SourceName))
   cbRedTray.Items.Add(New DataItem(pkSource.RawKind, pkSource.SourceName))
next
end sub

Sub PrintCover(byref MyCoversheet as String, byref Printer as String, byref RedTray as Long)
Dim oWord As Object = CreateObject("Word.Application")
Dim oDoc As Object = oWord.Documents.open(MyCoversheet)
.....

If InStr(oWord.ActivePrinter, Printer) = 0 Then
      With oWord.Dialogs.Item(wdDialogFilePrintSetup)
        .printer = Printer
        .donotsetassysdefault = True
        .Execute()
      End With
End If

 oDoc.PageSetup.FirstPageTray = RedTray 'Error occurs here
    oDoc.PageSetup.OtherPagesTray = RedTray
    oDoc.PrintOut(Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, Copies:=1)
    System.Threading.Thread.Sleep(1000)
end sub


从上方可以看出,在放置纸盘时会发生错误. Word必须提供一种方法,因为Word会为您提供打印机托盘,而与打印机无关...


As can be seen from above the error happens when setting the tray. There must be a way to do this as Word gives you the printer trays regardless of printer...

推荐答案

分辨率:
Word 2010期望使用整数而不是Long,这使我觉得我可能应该一直传递Integer值.
Resolution:
Word 2010 is expecting an integer rather than a Long which makes me think I maybe should have been passing Integer values all a long.


这篇关于通过vb.net在Word 2010中选择打印机纸盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆