vba 打印机问题
<p>偶用vba编了个识别图框块批量打图的程序,遇到两个问题,1,能预览图,但打印不出来;2,预览出来的是空白;请论坛里的各位高手指点指点,不胜感激,源码如下</p><p>用户窗体主要有两个combobox,两个optionbuttun,两个commandbuttun</p><p>Private Sub Command1_Click()<br/> On Error Resume Next<br/>Dim plotname As Variant<br/>Dim plotstyle As Variant<br/>Dim point1 As Variant, point2 As Variant<br/>Dim ent As AcadEntity<br/>Dim i As Integer<br/>Dim j As Integer<br/>Dim scs As String<br/>j = 0<br/>If Com1.ListIndex < 0 Or Com2.ListIndex < 0 Then<br/> MsgBox "请选择打印机和样式", vbOKOnly, "注意!"<br/>Else<br/> Me.Hide<br/> plotname = Com1.Text<br/> plotstyle = Com2.Text<br/> <br/> <br/> <br/> <br/> For Each ent In ThisDrawing.Application.ActiveDocument.ModelSpace<br/> If TypeOf ent Is AcadBlockReference Then<br/> ent.GetBoundingBox point1, point2<br/> ReDim Preserve point1(0 To 1)<br/> ReDim Preserve point2(0 To 1)<br/> Dim a As Double, b As Double<br/> a = Abs(Abs(point1(0)) - Abs(point2(0)))<br/> b = Abs(Abs(point1(1)) - Abs(point2(1)))<br/> If a > 0 Then<br/> scs = tk(a, b)<br/> If scs <> "0" Then<br/> If scs <> "A4" Then<br/> <br/> If Opt1.Value = True Then<br/> scs = "A3"<br/> End If<br/> End If<br/> <br/> With ThisDrawing.ActiveLayout<br/> <br/> .SetWindowToPlot point1, point2<br/> <br/> .ConfigName = plotname<br/> .StyleSheet = plotstyle<br/> .StandardScale = acScaleToFit<br/> .PaperUnits = acMillimeters<br/> .CanonicalMediaName = scs<br/> <br/> .GetWindowToPlot point1, point2<br/> <br/> If scs = "A4" Then<br/> .PlotRotation = ac0degrees<br/> Else<br/> .PlotRotation = ac90degrees<br/> End If<br/> End With<br/> <br/> If i <> 6 Then<br/> ThisDrawing.Plot.DisplayPlotPreview acFullPreview<br/> i = MsgBox("是否取消预览?" & "“是”取消预览全部打印,“否”继续预览,“取消”退出程序", vbYesNoCancel, "注意")<br/> If i = 2 Then<br/> j = j + 1<br/> Exit For<br/> End If<br/> End If<br/> j = j + 1<br/> ThisDrawing.ActiveLayout.PlotType = acWindow<br/> ThisDrawing.Application.ActiveDocument.SetVariable "BACKGROUNDPLOT", 0<br/> Debug.Print scs & ":" & a & "X" & b<br/> End If<br/> End If<br/> End If<br/> Next ent<br/> MsgBox "本次打印" & j & " 张图纸 ", vbOKOnly, "恭喜"<br/> Me.Show<br/> <br/>End If<br/>End Sub<br/>Private Sub Command2_Click()<br/>Unload Me<br/>End Sub<br/>Private Sub UserForm_Initialize()<br/>Dim plotDevices As Variant<br/>Dim plotsheets As Variant<br/> plotDevices = ThisDrawing.ActiveLayout.GetPlotDeviceNames()<br/> plotsheets = ThisDrawing.ActiveLayout.GetPlotStyleTableNames()<br/> Dim x As Integer<br/> Com1.Clear<br/> Com2.Clear<br/> For x = LBound(plotDevices) To UBound(plotDevices)<br/> Com1.AddItem plotDevices(x)<br/> Next<br/> For x = LBound(plotsheets) To UBound(plotsheets)<br/> Com2.AddItem plotsheets(x)<br/> Next<br/> Opt1.Value = True<br/>End Sub<br/>Function tk(xa As Double, ya As Double)<br/>On Error Resume Next<br/>tk = "0"<br/>If xa < ya Then<br/> If xa Mod 210 = 0 And ya Mod 297 = 0 Then<br/> tk = "A4"<br/> End If<br/>Else<br/> If xa Mod 1189 = 0 And ya Mod 841 = 0 Or xa * 2 Mod 1189 = 0 And ya * 2 Mod 841 = 0 Then<br/> tk = "A0"<br/> ElseIf xa Mod 841 = 0 And ya Mod 594 = 0 Or xa * 2 Mod 841 = 0 And ya * 2 Mod 594 = 0 Then<br/> tk = "A1"<br/> ElseIf xa Mod 594 = 0 And ya Mod 420 = 0 Or xa * 2 Mod 594 = 0 And ya * 2 Mod 420 = 0 Then<br/> tk = "A2"<br/> ElseIf xa Mod 420 = 0 And ya Mod 297 = 0 Or xa * 2 Mod 420 = 0 And ya * 2 Mod 297 = 0 Then<br/> tk = "A3"<br/> End If<br/>End If<br/>End Function<br/></p><p></p><p>补充 原程序如下</p><p></p>
页:
[1]