weixin7944 发表于 2007-9-27 09:46:00

关于网络打印机的问题

<p>最近我用VBA设计了一个批打印程序,遇到了一个问题:我使用的是局域网的打印机,其它的设置如打印机选择、打印方向、打印比表等都已经设计好了,并运行正确。但是,我不知道怎样选择网络打印机的纸张。在所有的纸张列表中就只有CAD默认的纸张列表(没有A3和A4),选择不了网络打印机的纸张列表,程序如下,请高手指点一下,怎样选择网络打印机的纸张。</p><p>Private Sub cmdCancel_Click()<br/>&nbsp;&nbsp;&nbsp; End<br/>End Sub</p><p>Private Sub cmdDelete_Click()<br/>&nbsp;&nbsp;&nbsp; '确认列表框包含列表项<br/>&nbsp;&nbsp;&nbsp; If lstFile.ListCount &gt;= 1 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '如果没有选中的内容,用上一次的列表项。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If lstFile.ListIndex = -1 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "请选择列表中的图形名称!"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lstFile.RemoveItem (lstFile.ListIndex)<br/>&nbsp;&nbsp;&nbsp; End If</p><p>End Sub</p><p>Private Sub cmdOk_Click()<br/>&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp; Dim ii As Integer<br/>&nbsp;&nbsp; Dim zz As Integer<br/>&nbsp;&nbsp; Dim drn As String<br/>&nbsp;&nbsp; Dim drn1 As String<br/>If lstFile.ListCount = 0 Then<br/>MsgBox "请添加所要操作的图形!"<br/>Exit Sub<br/>End If<br/>&nbsp;If ComboBox1.Text = "" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "请添加所要操作的图形!"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case (ComboBox1.Text)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Is = "HP-0"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AAPRINTER = "<a href="file://\\Plotter3\hp-0">\\Plotter3\hp-0</a>"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Is = "HP-1"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AAPRINTER = "<a href="file://\\Plotter3\hp-1">\\Plotter3\hp-1</a>"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Is = "HP-3"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AAPRINTER = "<a href="file://\\Plotter3\hp-3">\\Plotter3\hp-3</a>"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Is = "HP-4"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AAPRINTER = "<a href="file://\\Plotter4\hp-4">\\Plotter4\hp-4</a>"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select<br/>drn2 = TextBox2.Text<br/>zz = 1<br/>&nbsp;&nbsp; For ii = 1 To Len(drn2)<br/>&nbsp;&nbsp; ii = InStr(zz, drn2, Chr(92))<br/>&nbsp;&nbsp; If ii = 0 Then Exit For<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zz = ii + 1<br/>&nbsp;&nbsp; Next ii<br/>&nbsp;&nbsp; drn = Mid(drn2, zz)<br/>frmMain.hide<br/>For i = 0 To lstFile.ListCount - 1<br/>drn1 = lstFile.List(i)<br/>Application.Documents.Open drn1<br/>ThisDrawing.ActiveLayout.RefreshPlotDeviceInfo<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim currentPlot As AcadPlot<br/>&nbsp;&nbsp;&nbsp; Set currentPlot = ThisDrawing.Plot<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveLayout.PlotType = acExtents<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveLayout.StandardScale = acScaleToFit<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveLayout.StyleSheet = drn<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveLayout.PlotRotation = ac90degrees<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.ActiveLayout.CanonicalMediaName = ComboBox2.Text<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; currentPlot.PlotToDevice AAPRINTER<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.ActiveDocument.Close False, drn1<br/>Next i</p><p>End Sub</p><p>Private Sub cmdOpen_Click()<br/>&nbsp;&nbsp;&nbsp; On Error GoTo errHandle<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; Dim Y As Integer<br/>&nbsp;&nbsp;&nbsp; Dim z As Integer<br/>&nbsp;&nbsp;&nbsp; Dim FileNames() As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; With comDlg<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .CancelError = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .MaxFileSize = 32767<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .DialogTitle = "选择图形文件"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .filter = "图形文件(*.dwg)|*.dwg|所有文件(*.*)|*.*"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .FileName = ""<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ShowOpen<br/>&nbsp;&nbsp;&nbsp; End With<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; comDlg.FileName = comDlg.FileName &amp; Chr(0)&nbsp; '这些文件名是用空字符Chr(0)分隔符,而不是空格分隔符隔开<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; z = 1<br/>&nbsp;&nbsp;&nbsp; For i = 1 To Len(comDlg.FileName)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'InStr函数,返回 Variant (Long),指定一字符串在另一字符串中最先出现的位置。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '语法 InStr(起点位置, string1, string2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = InStr(z, comDlg.FileName, Chr(0))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If i = 0 Then Exit For<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve FileNames(Y)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Mid函数,返回 Variant (String),其中包含字符串中指定数量的字符。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '语法 Mid(string, start[, length])<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileNames(Y) = Mid(comDlg.FileName, z, i - z)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; z = i + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Y = Y + 1<br/>&nbsp;&nbsp;&nbsp; Next i</p><p>&nbsp;&nbsp;&nbsp; '向列表框中添加对象<br/>&nbsp;&nbsp;&nbsp; Dim count As Integer<br/>&nbsp;&nbsp;&nbsp; count = lstFile.ListCount<br/>&nbsp;&nbsp;&nbsp; If Y = 1 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lstFile.AddItem FileNames(count), 0<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To Y - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileNames(i) = FileNames(0) &amp; "\" &amp; FileNames(i)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lstFile.AddItem FileNames(i), i - 1 + count<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp;&nbsp; End If<br/>errHandle:<br/>End Sub</p><p></p><p></p><p>Private Sub CommandButton2_Click()<br/>On Error GoTo errHandle<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; Dim Y As Integer<br/>&nbsp;&nbsp;&nbsp; Dim z As Integer<br/>&nbsp;&nbsp;&nbsp; Dim FileNames() As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; With comDlg<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .CancelError = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .MaxFileSize = 32767<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .DialogTitle = "选择CTB文件"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .filter = "数据文件(*.ctb)|*.ctb|所有文件(*.*)|*.*"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .FileName = ""<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ShowOpen<br/>&nbsp;&nbsp;&nbsp; End With<br/>&nbsp;&nbsp; TextBox2.Text = comDlg.FileName<br/>errHandle:<br/>End Sub</p><p><br/>Private Sub UserForm_Initialize()<br/>&nbsp;&nbsp;&nbsp; lstFile.Clear<br/>&nbsp;&nbsp;&nbsp; ComboBox1.AddItem ("HP-0")<br/>&nbsp;&nbsp;&nbsp; ComboBox1.AddItem ("HP-1")<br/>&nbsp;&nbsp;&nbsp; ComboBox1.AddItem ("HP-3")<br/>&nbsp;&nbsp;&nbsp; ComboBox1.AddItem ("HP-4")<br/>&nbsp;&nbsp;&nbsp; ComboBox2.AddItem ("A3")<br/>&nbsp;&nbsp;&nbsp; ComboBox2.AddItem ("A4")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br/></p>
页: [1]
查看完整版本: 关于网络打印机的问题