Sub Macro1()
PrntChk = 1 '列印控制碼
UserForm1.Show
End Sub
活頁簿/程序區:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "工作表1" Then
If PrntChk <> 1 Then Cancel = True
End If
End Sub
FORM表單區:
Private Sub CommandButton1_Click()
If TextBox1 = "" Then Exit Sub
[B1] = TextBox1
With [B2]
.Formula = "=VLOOKUP(B1,'" & ThisWorkbook.Path & "\[資料庫.xls]員工資料表'!$A:$B,2,)"
.Value = .Value
End With
If IsError([B2]) Then
MsgBox "找不到符合的姓名! ": [B1:B2] = "": Exit Sub
Else
[A1:L48].Name = ActiveSheet.Name & "!Print_Area"
ActiveSheet.PrintOut
Unload Me
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
PrntChk = 0
End Sub