+ Reply to Thread
Results 1 to 2 of 2

Macro tweaking help for save to PDF using a location prompt but file name from cell

  1. #1
    Registered User
    Join Date
    02-27-2014
    Location
    Lewes
    MS-Off Ver
    Excel 2010
    Posts
    1

    Post Macro tweaking help for save to PDF using a location prompt but file name from cell

    Hi there,

    Brand new and an extreme novice so apologies.

    I have a macro that I have found online that allows me to save the active worksheet as a PDF, with the save as box popping up. I would like to amend it to still have the save as box pop up so a file location can be chosen, but to have the file name already populated using a concatenated formula in cell B383. Can anyone help me please?

    Here is the code:

    Function RDB_Create_PDF(Myvar As Object, FixedFilePathName As String, _
    OverwriteIfFileExist As Boolean, OpenPDFAfterPublish As Boolean) As String
    Dim FileFormatstr As String
    Dim Fname As Variant
    'Test to see if the Microsoft Create/Send add-in is installed.
    If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _
    & Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") <> "" Then
    If FixedFilePathName = "" Then
    'Open the GetSaveAsFilename dialog to enter a file name for the PDF file.
    FileFormatstr = "PDF Files (*.pdf), *.pdf"
    Fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _
    Title:="Create PDF")
    'If you cancel this dialog, exit the function.
    If Fname = False Then Exit Function
    Else
    Fname = FixedFilePathName
    End If
    'If OverwriteIfFileExist = False then test to see if the PDF
    'already exists in the folder and exit the function if it does.
    If OverwriteIfFileExist = False Then
    If Dir(Fname) <> "" Then Exit Function
    End If
    'Now export the PDF file.
    On Error Resume Next
    Myvar.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    FileName:=Fname, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=OpenPDFAfterPublish
    On Error GoTo 0
    'If the export is successful, return the file name.
    If Dir(Fname) <> "" Then RDB_Create_PDF = Fname
    End If
    End Function

    Sub RDB_Worksheet_Or_Worksheets_To_PDF()
    Dim FileName As String
    If ActiveWindow.SelectedSheets.Count > 1 Then
    MsgBox "There is more than one sheet selected," & vbNewLine & _
    "and every selected sheet will be published."
    End If
    'Call the function with the correct arguments.
    'You can also use Sheets("Sheet3") instead of ActiveSheet in the code(the sheet does not need to be active then).
    FileName = RDB_Create_PDF(ActiveSheet, "", True, True)
    'For a fixed file name and to overwrite it each time you run the macro, use the following statement.
    'RDB_Create_PDF(ActiveSheet, "", True, True)
    If FileName <> "" Then
    'Uncomment the following statement if you want to send the PDF by e-mail.
    'RDB_Mail_PDF_Outlook FileName, "[email protected]", "This is the subject", _
    "See the attached PDF file with the last figures" _
    & vbNewLine & vbNewLine & "Regards Ron de bruin", False
    Else
    MsgBox "It is not possible to create the PDF; possible reasons:" & vbNewLine & _
    "Add-in is not installed" & vbNewLine & _
    "You canceled the GetSaveAsFilename dialog" & vbNewLine & _
    "The path to save the file is not correct" & vbNewLine & _
    "PDF file exists and you canceled overwriting it."
    End If
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro tweaking help for save to PDF using a location prompt but file name from cell

    Hi, cleol56,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  2. [SOLVED] Macro to prompt user for folder location and save acitve workbook.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2013, 06:20 PM
  3. Macro with cell reference as a name, but prompt for save location and save as csv
    By tomham in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-15-2012, 06:21 PM
  4. Macro to prompt user for file name and save in location
    By Fungijus in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-21-2011, 02:16 PM
  5. Save as macro with location prompt but fixed file name ?
    By Simon-ch in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-31-2008, 07:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1