|
本帖最后由 宝石山人 于 2018-9-8 15:21 编辑
请教大侠
我在同一窗体分别用控件进行预览
commanbutton1
在基本工作簿上可预览各表,正常运行
for i=1 to 3
sheets(i).activate
ActiveWindow.SelectedSheets.PrintPreview
next
commanbutton2
打开已有工作表
UserForm1.Hide
Path1 = ActiveWorkbook.Path
Workbooks.Open Filename:=Path1 & "\??λ??.xls"
fName = ActiveWorkbook.Name
Cells(5 - 2, 1) = "??" & Str(Lunsu) & " ??????????"
Cells(5 - 1, 4) = CDate(Now())
If InStr("???????", XianM) Then
ActiveCell = "SNλ"
ActiveCell.Offset(0, 2) = "EWλ"
End If
‘ **** 根据版本
If Application.Version < 12 Then
ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.Close (False)
Else
’ ***** 此时如单步可预览,
‘ 而运行时,则快速通过,无法和打印
Windows(fName).Activate
ActiveWindow.SelectedSheets.PrintPreview (True)
End If
Application.ScreenUpdating = True
ActiveWorkbook.Close False
UserForm1.Show
我在简易窗体中能正常运行,到复杂窗体时不能运行,见下
Me.Hide
Path1 = "C:\zj": Path2 = ActiveWorkbook.Path
Workbooks.Open FileName:=Path1 & "\?????????????.xls"
VBA.ChDir Path1
Cells(5 - 2, 1) = "??" & Str(LunSu) & " ??????????"
Cells(5 - 1, 4) = CDate(Now())
If InStr("???????", XianM) Then
ActiveCell = "SNλ"
ActiveCell.Offset(0, 2) = "EWλ"
End If
For i1 = 1 To Table ’ 填写内容
Cells(5 + i1, 1) = "??" & Str(i1 + i2 - 1) & " ??"
If Dnum(i1, 5) > " " Then
Cells(5 + i1, 2) = Dnum(i1, 3) & "(" & Dnum(i1, 5) & ")"
Else
Cells(5 + i1, 2) = Dnum(i1, 3)
End If
Cells(5 + i1, 3) = "Vs"
If Dnum(i1, 6) > " " Then
Cells(5 + i1, 4) = Dnum(i1, 4) & "(" & Dnum(i1, 6) & ")"
Else
If Dnum(i1, 4) > " " Then
Cells(5 + i1, 4) = Dnum(i1, 4)
Else
Cells(5 + i1, 4) = "???"
End If
End If
Cells(5 + i1, 5) = Dnum(i1, 1)
Cells(5 + i1, 6) = Dnum(i1, 2)
Next
‘ 以下预览
If Application.Version < 12 Then
ActiveWindow.SelectedSheets.PrintPreview
Else
Windows(Path1 & "\?????????????.xls").Activate
With Selection
ActiveWindow.SelectedSheets.PrintPreview (True)
End With
VBA.ChDir Path2
End If
请问:出错在哪儿?
谢谢指教
|
|