Em chào thầy (cô), anh (chị) trên GPE.
Em có sưu tầm được Form in trên diễn đàn GPE.
Em lắp vào file để sử dụng, do em không biết về code thấy báo lỗi.
Nhờ các thầy (cô), anh(chị) sửa giúp em code để có thể in được.
Em xin chân thành cảm ơn!
Code em sử dụng trong form:


Em có sưu tầm được Form in trên diễn đàn GPE.
Em lắp vào file để sử dụng, do em không biết về code thấy báo lỗi.
Nhờ các thầy (cô), anh(chị) sửa giúp em code để có thể in được.
Em xin chân thành cảm ơn!
Code em sử dụng trong form:
Mã:
Private Sub CommandButton1_Click()
BBLM.Hide
Dim a As Integer
Dim b As Integer
Dim N As Long, NameSh As String
NameSh = ActiveSheet.Name
If NameSh = "Bang" Then
a = TextBox1
b = TextBox2
For a = a To b
Range("G8") = a
FixRow Range("D11,D12,D13,D14,D15")
'ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut , ActivePrinter:=ComboBox1, Copies:=1, Collate:=True
Next
Else
'ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut , ActivePrinter:=ComboBox1, Copies:=1, Collate:=True
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Sub List_Printer()
Dim aPrinters As Object
Dim I As Long, N As Long
With CreateObject("WScript.Network")
Set aPrinters = .EnumPrinterConnections
For I = 1 To aPrinters.Count Step 2
ComboBox1.AddItem aPrinters.Item(I)
Next
End With
End Sub
Sub Get_Default_Printer()
Dim WSHshell As Object, RegKey As String, RegKeySplit As Variant
Dim RegDefault As String, MyPrinter As String
RegKey = _
"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
Set WSHshell = CreateObject("WScript.Shell")
RegDefault = WSHshell.RegRead(RegKey)
Set WSHshell = Nothing
'Get name default printer:
RegKeySplit = Split(RegDefault, ",")
MyPrinter = RegKeySplit(0)
ComboBox1.Text = MyPrinter
End Sub
Private Sub Printer_Properties_Click()
Call Shell("rundll32 printui.dll,PrintUIEntry /p /n """ & ComboBox1.Value & """", vbNormalFocus)
End Sub
Private Sub UserForm_Initialize()
Call List_Printer
Call Get_Default_Printer
End Sub


File đính kèm
Lần chỉnh sửa cuối: