In PDF theo danh sách Excel từ nhiều Folder (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

eneennn

Thành viên mới
Tham gia
22/12/21
Bài viết
1
Được thích
0
Các anh chị ơi, cho em hỏi.

Em có đọc được bài hướng dẫn của bạn này ý ạ. Nhưng vấn đề của e là Folder PKN được chia nhỏ ra thành từng ngày như này.

Thì code nên sửa lại như thế nào ạ ??? Vì công việc hiện tại của e phải in tầm 10 hóa đơn theo danh sách excel, trong 1 tháng 24 ngày. Tổng cộng trên 10.000 hóa đơn nên k thể gộp thành 1 folde được ý ạ.

Code được ghi trong bài ạ. https://www.giaiphapexcel.com/diendan/threads/in-file-pdf-theo-danh-sách-trong-excel.141026/

Option Explicit
#If VBA7 Then
Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
#Else
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If
Public Function PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim X
X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function

Sub testPrint()
Dim printThis, Arr()
Dim strDir As String
Dim i As Integer
strDir = ThisWorkbook.Path & "\PKN\"
Arr = Sheet2.Range("C2:C" & Sheet2.Range("C65000").End(xlUp).Row).Value
For i = 1 To UBound(Arr)
printThis = PrintThisDoc(0, strDir & Arr(i, 1) & ".PDF")
Next i
End Sub

E cảm ơn mọi người ạ
test.png

 
Bạn thử đoạn code này xem được không nhé. Kết hợp mở hộp thoại Open để chọn thư mục
Mã:
Sub testPrint()
    Dim printThis, Arr()
    Dim strDir As String
    Dim i As Integer
    Dim Folder_Baby As String
    With Application.FileDialog(msoFileDialogFolderPicker)  'FileDialog(3) la hop thoai Open
        .AllowMultiSelect = False                           '.AllowMultiSelect = False thi cho phep chi chon 1 file / True cho phep chon nhieu file
        If .Show = -1 Then
            For i = 1 To .SelectedItems.Count
                Folder_Baby = .SelectedItems.Item(1)
            Next
        End If
    End With
    strDir = Folder_Baby & "\"
    Arr = Sheet2.Range("C2:C" & Sheet2.Range("C65000").End(xlUp).Row).Value
    For i = 1 To UBound(Arr)
        printThis = PrintThisDoc(0, strDir & Arr(i, 1) & ".PDF")
    Next i
End Sub
 
Bạn thử đoạn code này xem được không nhé. Kết hợp mở hộp thoại Open để chọn thư mục
Mã:
Sub testPrint()
    Dim printThis, Arr()
    Dim strDir As String
    Dim i As Integer
    Dim Folder_Baby As String
    With Application.FileDialog(msoFileDialogFolderPicker)  'FileDialog(3) la hop thoai Open
        .AllowMultiSelect = False                           '.AllowMultiSelect = False thi cho phep chi chon 1 file / True cho phep chon nhieu file
        If .Show = -1 Then
            For i = 1 To .SelectedItems.Count
                Folder_Baby = .SelectedItems.Item(1)
            Next
        End If
    End With
    strDir = Folder_Baby & "\"
    Arr = Sheet2.Range("C2:C" & Sheet2.Range("C65000").End(xlUp).Row).Value
    For i = 1 To UBound(Arr)
        printThis = PrintThisDoc(0, strDir & Arr(i, 1) & ".PDF")
    Next i
End Sub
Hình như chưa đúng yêu cầu của chủ thớt.
 
Web KT

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

Back
Top Bottom