简体   繁体   中英

How to insert multiple values in a single excel cell and export it as a pdf for every entry of that cell

i want to insert multiple values in a single cell and export every single entry as a separate pdf. The only thing i did till know is to manually reference the cells and export them as pdfs. This is my macro:

 Sub SavePDF()
     Range("A8").Value = Range("A8").Value + 1
        Sheet3.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:="C:\Users\Report_" & _
            ActiveSheet.Range("A8").Value & ".pdf", _
            OpenAfterPublish:=False
    End Sub

Lets say that i have a range: M6:M14 and i want to input the results in the cell "M1". After i start the macro i want ot create for every single value (the value should be inside the pdf) a new pdf. Example: for the value of M6 a pdf, for M7 another and so on till i reach M14.

在此处输入图片说明

Please try this code.

Sub SavePDF()

    Dim NameRange As Range
    Dim i As Integer
    Dim PdfName As String

    Set NameRange = Range("M6:M14")

    For i = 1 To NameRange.Cells.Count
        PdfName = Trim(Range("A8").Value) & i
        With Sheet3
            .Range("M1").Value = NameRange.Cells(i).Value
            .ExportAsFixedFormat _
             Type:=xlTypePDF, _
             Filename:="C:\Users\Report_" & PdfName & ".pdf", _
             OpenAfterPublish:=False
        End With
    Next i
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM