返回列表 上一主題 發帖

一個列印問題請求協助

用2003版寫一個, 自行套看看:
  1. Private Sub CommandButton1_Click()
  2. If TextBox1 = "" Then Exit Sub
  3. [B1] = TextBox1
  4. With [B2]
  5.      .Formula = "=VLOOKUP(B1,'" & ThisWorkbook.Path & "\[資料庫.xls]員工資料表'!$A:$B,2,)"
  6.      .Value = .Value
  7. End With
  8. If IsError([B2]) Then
  9.     MsgBox "找不到符合的姓名! ": [B1:B2] = "": Exit Sub
  10. Else
  11.    Unload Me
  12.    [A1:L48].Name = ActiveSheet.Name & "!Print_Area"
  13.    ActiveSheet.PrintOut
  14. End If
  15. End Sub
複製代碼


mm01.rar (21.65 KB)

TOP

回復 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)

TOP

回復 7# hong912


再加個變數即可:
mm03.rar (23.52 KB)

TOP

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題