- 帖子
- 2848
- 主題
- 10
- 精華
- 0
- 積分
- 2903
- 點名
- 0
- 作業系統
- 〔略〕
- 軟體版本
- 〔略〕
- 閱讀權限
- 100
- 性別
- 男
- 來自
- 〔略〕
- 註冊時間
- 2013-5-13
- 最後登錄
- 2026-7-25
|
回復 4# 317
要幾個程序:
模組區:
Public PrntChk%
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
mm02.rar (23.25 KB)
|
|