Kiểm tra lệnh in của máy in đã thực hiện xong chưa

Liên hệ QC

forpromise2013

Thành viên mới
Tham gia
2/1/18
Bài viết
28
Được thích
4
Giới tính
Nam
Em chào các anh chị ạ.
Em cần phải in ấn nhiều file pdf và excel. Code của em chạy bình thường không xảy ra lỗi. Chỉ có điều là em cần phải in theo thứ tự, đoạn code của em cũng sắp xếp in theo thứ tự nhưng do lệnh in đc gửi đến máy in lại lộn xộn nên khi chạy code xong không dc như ý muốn.
Vậy có cách nào để kiểm tra lệnh in trước đã in xong chưa rồi mới cho chạy code in file tiếp theo không ạ?
Hoặc có cách nào code lại để lệnh in đc gửi tới máy in đúng theo thứ tự cần in không ạ.
Em cảm ơn các anh chị ạ!
 
có cách nào để kiểm tra lệnh in trước đã in xong chưa
Có.
1/ Mở trình điều khiển máy in lên xem;
2/ (hoặc) Bản in chui hết ra khỏi máy in tức là in xong.
đoạn code của em cũng sắp xếp in theo thứ tự nhưng do lệnh in đc gửi đến máy in lại lộn xộn nên khi chạy code xong không dc như ý muốn.
Gửi khúc code đó lên đây.

Mấy chữ "dờ cờ" là dòng điện một chiều đó hả?
 
Upvote 0
Êêê, gõ thiếu kìa. Hoặc kẹt phím :D

Gõ thiếu .................................................................................................... *
 
Upvote 0
Có.
1/ Mở trình điều khiển máy in lên xem;
2/ (hoặc) Bản in chui hết ra khỏi máy in tức là in xong.

Gửi khúc code đó lên đây.

Mấy chữ "dờ cờ" là dòng điện một chiều đó hả?
Đoạn code của em đây ạ:

Public num_of_row As Integer
Public ten1, ten2, tenfilepdf, tenfileexcel As String
-------------------------------------------------
Sub taoFILE()
Dim objfso As Object
Dim objfolder As Object
Dim objfile As Object
Dim i, j, n As Integer
Dim DD, ten1, ten2, tenfilepdf, tenfileexcel As String
Dim wb As Workbook
DD = Cells(3, 2).Text
Set objfso = CreateObject("scripting.filesystemobject")
Set objfolder = objfso.getfolder(DD)
For Each objfile In objfolder.Files
If objfile.Type = "Adobe Acrobat Document" Then
Cells(i + 7, 2) = objfile.Name
i = i + 1
Else
End If
If objfile.Type = "Microsoft Excel 97-2003 Worksheet" Then
Cells(j + 7, 3) = objfile.Name
j = j + 1
Else
End If
Next

num_of_row = Cells(Rows.Count, "B").End(xlUp).Row - 6

For l = 1 To num_of_row
Cells(l + 6, 4) = "=MID(B" & (l + 6) & ",SEARCH(" & 30 & ",B" & (l + 6) & "),12)"
Cells(l + 6, 5) = "=MID(C" & (l + 6) & ",SEARCH(" & 30 & ",C" & (l + 6) & "),12)"
Next
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range _
("D6"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Range(Cells(7, 2), Cells(num_of_row + 7, 2)).Copy
Cells(num_of_row + 15, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range _
("E6"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range(Cells(7, 3), Cells(num_of_row + 7, 3)).Copy
Cells(num_of_row + 15, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

------------------------------

Sub inPDF()
Dim k As Integer
For k = 1 To num_of_row

tenfilepdf = Cells(3, 2).Text & Application.PathSeparator & Cells(k + num_of_row + 14, 8).Text
With CreateObject("Shell.Application")
For n = 1 To 2
.Namespace(0).ParseName(tenfilepdf).InvokeVerb ("Print")
Next
End With
Application.Wait (Now + 3 / 24 / 60 / 60)

Cells(k, "F") = "DONE!"
Next
Application.Wait (Now + 3 / 24 / 60 / 60)
MsgBox "Da in xong"
End Sub

--------------------------

Sub inExcel()
Dim e As Integer

For e = 1 To num_of_row
tenfileexcel = Cells(3, 2).Text & Application.PathSeparator & Cells(e + num_of_row + 14, 9).Text
ten2 = Cells(e + num_of_row + 14, 9).Text
Workbooks.Open Filename:=tenfileexcel
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=2, Copies:=2, Collate _
:=True, IgnorePrintAreas:=False
Workbooks(ten2).Close
Application.Wait (Now + 2 / 24 / 60 / 60)
Cells(e, "G") = "DONE!"

Next
MsgBox "Da in xong"
End Sub
 
Upvote 0
Các anh chị trong diễn đàn có ai giúp em vấn đề này với ah. Huhu
 
Upvote 0
Các anh chị trong diễn đàn có ai giúp em vấn đề này với ah. Huhu
Thử xem nhé.

Mã:
Function PrinterStatus() As String
Dim objWMIService
Dim Printers
Dim objPrinter
Dim sDefault As String
    
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    
    Set Printers = objWMIService.ExecQuery("Select * from Win32_Printer where Default = 'True'")
    For Each objPrinter In Printers
        sDefault = objPrinter.Name
    Next
    
    Set Printers = objWMIService.ExecQuery("Select * from Win32_Printer")
                               
    For Each objPrinter In Printers
        If objPrinter.Name = sDefault Then
            Select Case objPrinter.PrinterStatus
            Case 3
                PrinterStatus = "Idle"
            Case 4
                PrinterStatus = "Printing"
            Case 5
                PrinterStatus = "Warming up"
            Case Else
                PrinterStatus = "off line"
            End Select
            Exit For
        End If
    Next
End Function

Trong code
Mã:
If PrinterStatus <> "Idle" Then ... chờ thêm chút
 
Upvote 0
Thử xem nhé.

Mã:
Function PrinterStatus() As String
Dim objWMIService
Dim Printers
Dim objPrinter
Dim sDefault As String
   
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
   
    Set Printers = objWMIService.ExecQuery("Select * from Win32_Printer where Default = 'True'")
    For Each objPrinter In Printers
        sDefault = objPrinter.Name
    Next
   
    Set Printers = objWMIService.ExecQuery("Select * from Win32_Printer")
                              
    For Each objPrinter In Printers
        If objPrinter.Name = sDefault Then
            Select Case objPrinter.PrinterStatus
            Case 3
                PrinterStatus = "Idle"
            Case 4
                PrinterStatus = "Printing"
            Case 5
                PrinterStatus = "Warming up"
            Case Else
                PrinterStatus = "off line"
            End Select
            Exit For
        End If
    Next
End Function

Trong code
Mã:
If PrinterStatus <> "Idle" Then ... chờ thêm chút
Trong đoạn sub này của em:
Sub inPDF()
Dim k As Integer
For k = 1 To num_of_row

tenfilepdf = Cells(3, 2).Text & Application.PathSeparator & Cells(k + num_of_row + 14, 8).Text
With CreateObject("Shell.Application")
For n = 1 To 2
.Namespace(0).ParseName(tenfilepdf).InvokeVerb ("Print")
Next
End With
Application.Wait (Now + 3 / 24 / 60 / 60)

Cells(k, "F") = "DONE!"
Next
Application.Wait (Now + 3 / 24 / 60 / 60)
MsgBox "Da in xong"
End Sub

thì việc in file PDF bị lộn xộn, có file thì chỉ in ra được có 1 bản.
đoạn code :
For n = 1 To 2
.Namespace(0).ParseName(tenfilepdf).InvokeVerb ("Print")
Next

là em muốn in 2 bản của từng file .
để tránh việc in lộn xộn và in được 2 bản thì em để hàm PrinterStatus ở đâu trong đoạn code trên thì được ạ.
 
Upvote 0
Lần trước đã chỉ cho viết công thức, code vào chỗ nào rồi mà còn không chịu làm theo. Nhìn mớ trên lộn xộn lắm bạn à.

------
Diễn đàn dạo này bết bát quá, tình hình có vẻ hơi căng.
 
Upvote 0
Anh ơi! Em chưa nhận được hướng dẫn ạ.

Bạn còn đóng khung bài đó lại kìa, giờ kêu chưa nhận được nghe như mình thiếu trách nhiệm gửi cho bạn vậy. Có vẻ thêm một người có quan điểm đăng chủ để hỏi là đem lại ý nghĩa (...) cho thành viên khác chăng?

Screenshot_2018-11-01-21-47-06_1.jpg
 
Upvote 0
Bạn còn đóng khung bài đó lại kìa, giờ kêu chưa nhận được nghe như mình thiếu trách nhiệm gửi cho bạn vậy. Có vẻ thêm một người có quan điểm đăng chủ để hỏi là đem lại ý nghĩa (...) cho thành viên khác chăng?

View attachment 206853
Em nhớ bài viết này rồi. Bài viết này nằm trong topic em nhờ các anh chị xóa sheet ẩn.
Em không có ý nói anh thiếu trách nhiệm trong việc gửi đâu ạ, có gì sơ sót mong anh bỏ qua ạ.
Em thành thật xin lỗi ạ!
 
Upvote 0
ý Anh @befaint như thế này nè bạn! để dễ nhìn và đọc đó bạn.
PHP:
Sub inPDF()
Dim k As Integer
For k = 1 To num_of_row

tenfilepdf = Cells(3, 2).Text & Application.PathSeparator & Cells(k + num_of_row + 14, 8).Text
With CreateObject("Shell.Application")
For n = 1 To 2
.Namespace(0).ParseName(tenfilepdf).InvokeVerb ("Print")
Next
End With
Application.Wait (Now + 3 / 24 / 60 / 60)

Cells(k, "F") = "DONE!"
Next
Application.Wait (Now + 3 / 24 / 60 / 60)
MsgBox "Da in xong"
End Sub
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom