+ Reply to Thread
Results 1 to 8 of 8

Merging two parts of VBA code (save as PDF)

  1. #1
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Merging two parts of VBA code (save as PDF)

    Hi All,

    I need merge two bits of code to:

    1). Save the Active sheet to a certain file whilst using data from B16 and F10 to save as its file name.

    2). Save as PDF.

    The first bit of code works perfectly, but I just need it to save as a PDF. I have pasted the codes below to look at, and if anyone could help out it would be much appreciated...Thanks in advance. Carl

    Sub SaveActivesheet()

    Const strPath As String = "C:\Documents and Settings\carl.walker\My Documents\Reports\"
    Dim strFile As String

    With Sheet2
    'check for Account Details'
    If .Range("B16").Value = "" Or .Range("F10").Value = "" Then
    MsgBox "Please enter Account Details by using the Add Account Details Userform provided. ", _
    vbExclamation, "Missing Account"
    Else
    strFile = .Range("B16").Value & " " & .Range("F10").Value & ".xlsx"
    .Copy 'Copy sheet2 to a new workbook
    ActiveSheet.SaveAs Filename:=strPath & strFile 'Save the new workbook
    End If
    End With

    End Sub


    Sub SavePDFMacro()

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Documents and Settings\carl.walker\My Documents\Reports", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
    End Sub



    Regards
    Carl

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Merging two parts of VBA code (save as PDF)

    I have just saved a file as a pdf

    and recorded the following:-

    Please Login or Register  to view this content.
    So I am sure that your code works, except your will try and open the PDF file and mine didn't ( Unless I change the last false to True ).



    So I don't see your problem.
    This should work.


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Merging two parts of VBA code (save as PDF)

    Hi Mehmetcik,

    Sorry, what I should of said is that I would like the first code to work but instead of it saving in xlsx format, to save as PDF instead.

    Regards
    Carl

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Merging two parts of VBA code (save as PDF)

    Try this.



    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Merging two parts of VBA code (save as PDF)

    Hi Mehmetcik,

    The code converts to pdf which is great, but it does not use the data from fields B16 and F10 to save as its filename.

    Hope this helps

    Regards
    Carl

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Merging two parts of VBA code (save as PDF)

    Hi Carl

    Try this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  7. #7
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Merging two parts of VBA code (save as PDF)

    Hi John,

    That works a treat, thanks very much!

    Kind Regards
    Carl

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Merging two parts of VBA code (save as PDF)

    You're welcome...glad I could help. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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