insert stamp and print to PDF

phuongnguyenvpvn

New Member
Joined
Apr 14, 2022
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Dear Everyone
now i had one VBA code auto insert the stamp and print to excel
before my code insert stamp to Range("D52:G64") and print to PDF Print Area = "A1:J64"
now i would like to insert stamp to end row have character of A column and Print Area = A1 to end row have character of A column + 12 row

Please help me modifies this code and many thanks!
VBA Code:
Sub Update()
    On Error GoTo lLOI
    Call Update_
    MsgBox "Hoan thanh viec xuat file."
lthoat:
    Exit Sub
lLOI:
    MsgBox Err.Description
    Resume lthoat
End Sub
Private Sub Update_()
    Dim vFileSelect As Variant
    Dim objFso As Scripting.FileSystemObject
    Dim strFolder As String
    Dim strConDau As String
    Dim vNameP As Variant, avData()
    Dim lgI As Long
    Dim avInfo(), wbFile As Workbook, wsFile As Worksheet, lgIndexFile As Long, vFile, strFilePDF As String
    vFileSelect = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*,All Files (*.*),*.*", _
                                            Title:="Chon cac file", _
                                            MultiSelect:=True)
    If VBA.VarType(vFileSelect) = vbBoolean Then Exit Sub
    On Error GoTo lLOI
    Set objFso = New Scripting.FileSystemObject
100
    strFolder = ThisWorkbook.Path & Application.PathSeparator & VBA.Format(VBA.Now, "yyymmdd_hhmmss")
    If objFso.FolderExists(strFolder) = False Then
        objFso.CreateFolder strFolder
    End If
    strFolder = strFolder & Application.PathSeparator
120
    strConDau = Sheet1.Range("B1").Value
    If Not objFso.FileExists(strConDau) Then
        Err.Raise vbObjectError + 512 + 10, , "File con dau khong ton tai:" & strConDau
    End If
130
    ReDim avInfo(1 To UBound(vFileSelect) - LBound(vFileSelect) + 1, 1 To 3)
    For Each vFile In vFileSelect
        lgIndexFile = lgIndexFile + 1
        avInfo(lgIndexFile, 1) = vFile
140
        Set wbFile = Application.Workbooks.Open(vFile, False, True)
        Set wsFile = wbFile.Worksheets(1)
150
        With wsFile.Range("D52:G64")
            wsFile.Shapes.AddPicture strConDau, msoCTrue, msoCTrue, .Left, .Top, .Width, .Height
        End With
160
'        With wsFile.Range("A31")
'            .Value = "'" & .Value
'        End With
        lgI = lgI
        
170

        avData = wsFile.Range("A1:A100").Value
        strFilePDF = ""
        For lgI = 1 To UBound(avData)
            If VBA.LCase(avData(lgI, 1)) Like "*invoice no*date*" Then
                vNameP = VBA.Split(avData(lgI, 1), ":")
                vNameP = VBA.Trim(vNameP(1))
                vNameP = VBA.Split(vNameP, " ")
                vNameP = vNameP(0)
                strFilePDF = strFolder & vNameP & ".pdf"
                avInfo(lgIndexFile, 2) = strFilePDF
            End If
            If VBA.VarType(avData(lgI, 1)) = vbDouble Then
                wsFile.Range("A" & lgI).Value = "'" & avData(lgI, 1)
            End If
            
        Next
        If strFilePDF = "" Then
            Err.Raise vbObjectError + 512 + 10, , "Khong the tim thay invoice"
        End If
175
        wsFile.PageSetup.PrintArea = "A1:A"
        wsFile.PageSetup.Zoom = False
        wsFile.PageSetup.FitToPagesWide = 1
        wsFile.PageSetup.FitToPagesTall = 1
180
        wsFile.ExportAsFixedFormat xlTypePDF, strFilePDF
        avInfo(lgIndexFile, 3) = "OK"
300
lNextFile:
        wbFile.Close False
        Set wbFile = Nothing
        Set wsFile = Nothing
        
    Next

    With Application.Workbooks.Add(xlWorksheet).Worksheets(1)
        .Range("A2").Resize(lgIndexFile, 3).Value = avInfo
    End With

lthoat:
    Exit Sub
lLOI:
    Select Case VBA.Erl
        Case 100
            Err.Raise vbObjectError + 512 + 10, , "Loi khi tao thu muc chua ket qua." & vbNewLine & _
            Err.Description
        Case 120
            Err.Raise vbObjectError + 512 + 10, , "Loi khi xac dinh file con dau." & vbNewLine & _
            Err.Description
        Case 140
            avInfo(lgIndexFile, 2) = Err.Description
            Resume lNextFile
        Case 150
            avInfo(lgIndexFile, 2) = "Loi khi chen anh con dau." & vbNewLine & Err.Description
            Resume lNextFile
        Case 175
            avInfo(lgIndexFile, 2) = "Loi khi cai dat vung in." & vbNewLine & Err.Description
            Resume lNextFile
        Case 170
            avInfo(lgIndexFile, 2) = "Loi khi xac dinh ten file pdf." & vbNewLine & Err.Description
            Resume lNextFile
        Case 180
            avInfo(lgIndexFile, 2) = "Khong the xuat file pdf." & vbNewLine & Err.Description
            Resume lNextFile
        Case 300
            Resume Next
    End Select
    
    
    
End Sub

Dear Everyone
now i had one VBA code auto insert the stamp and print to excel
before my code insert stamp to Range("D52:G64") and print to PDF Print Area = "A1:J64"
now i would like to insert stamp to end row have character of A column and Print Area = A1 to end row have character of A column + 12 row

Please help me modifies this code and many thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top