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