Results 1 to 9 of 9

Thread: Issue saving Excel Worksheet to .pdf

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Newbie
    Joined
    Mar 2024
    Posts
    4
    Location
    I tried that and it saved the .pdf as the file name that I specified. But if I want to save the file name based on a cell in this instance cell M5 it does not save. Also when I set the print area for the macro it is saving 26 pages and not just one. Below is the updated Macro:
    Sub Printpdf()
        ' Printpdf Macro
        ' Saves each sheet as a pdf
        ' Keyboard Shortcut: Ctrl+w
        ' Set X = 6 for start of loop
        x = 6
        Do Until x = 250
             ' Check for blank row in data sheet and stop looping
             Sheets("data sheet").Select
             Cells(x, 1).Select
             If Cells(x, 1) = 0 Then
                 x = 250
              Else
                  Sheets("scorecard").Select
                  ' Copy Supplier name from "data sheet" row "x" to "scorecard" sheet
                  Sheets("data sheet").Select
                 Cells(x, 1).Select
                 Selection.Copy
                 Sheets("scorecard").Select
                 Range("E2").Select
                 ActiveSheet.Paste
                 ' Set variable s equal to supplier name in "scorecard" sheet
                 s = Range("M5").Value
                 ' Save the sheet as a pdf with the name "s"
                 Dim Path, FileName1 As String
                 Path = "C:\Users\kpost\Downloads\PDFTest" '<-- edit path as required.
                 FileName1 = Sheet1.Range("M5").Value '<-- edit cell target as required.
                 ' Save active workbook as PDF
                 ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & FileName1 & ".pdf", OpenAfterPublish:=False
                 ' Increment value of x for loop
                 x = x + 1
             End If
        Loop
    End Sub
    Last edited by Aussiebear; 05-16-2025 at 02:51 AM. Reason: Added code tags to suppplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •