+ Reply to Thread
Results 1 to 10 of 10

Trouble with macros to save excel spreadsheet at PDF

  1. #1
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    756

    Trouble with macros to save excel spreadsheet at PDF

    Hello,

    I am having trouble with macros, as I need to write one which saves an excel spreadsheet as a PDF, to the folder specified by the hyperlink in cell D27 and under the name based on a combination of cells F12, F13 and F14.

    Can anyone help please?


    Many thanks,


    Chris

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Trouble with macros to save excel spreadsheet at PDF

    Chris

    What have you tried and what problems have you had?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    756

    Re: Trouble with macros to save excel spreadsheet at PDF

    Hello,

    I have tried many of them and I have deleted the one which was working best. I got as far as being able to convert the spreadsheet as a PDF, but I want it to be saved to the destination as specified as a hyperlink in cell D27 and under a name specified by a combination of the values in F12, F13 and F14.

    cheers

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Trouble with macros to save excel spreadsheet at PDF

    It should be straightforward apart from the hyperlink part.

    What exactly is in D27?

  5. #5
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    756

    Re: Trouble with macros to save excel spreadsheet at PDF

    In D27 is =HYPERLINK("H:\LOS\Investigations\"&F14) and in F14 is the name of a specific store, so when the spreadsheet is saved, it goes into the correct folder for the relevant store.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Trouble with macros to save excel spreadsheet at PDF

    You don't say how F12, F13 and F14 should be combined to give the filename but here's an example where they values in those cells are simply concatenated.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    756

    Re: Trouble with macros to save excel spreadsheet at PDF

    I have tried using this macro:

    Sub SaveAsPDF()
    'Saves active worksheet as pdf using concatenation
    'of F12,F13,F14

    Dim fName As String
    With ActiveWorkbook.ExportAsFixedFormat xlTypePDF, Range("D27").Value & "\" & Range("F12").Value & Range("F13").Value & Range("F14").Value
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "D27" & fName, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With
    End Sub

    I am getting the error "Compile error: Syntax error" and it highlights the top line in yellow.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Trouble with macros to save excel spreadsheet at PDF

    Start with this and don't forget to assign value to fName.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  9. #9
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    756

    Re: Trouble with macros to save excel spreadsheet at PDF

    Hi bakerman2, what do you mean when you say assign a value to fName? What kind of value do i put in there?

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Trouble with macros to save excel spreadsheet at PDF

    This is shorter.
    Please Login or Register  to view this content.
    So fName must end up with all elements combined to create fullpath and name for the sheet you want to save.

+ 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. Trouble with homemade retail excel spreadsheet
    By DIPPYDOR in forum Excel General
    Replies: 1
    Last Post: 09-29-2014, 07:59 AM
  2. [SOLVED] Trouble with Macros in Excel 2010
    By mosswood17 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2013, 05:51 PM
  3. Having trouble converting an excel spreadsheet into a database
    By RCope in forum Access Tables & Databases
    Replies: 1
    Last Post: 12-18-2012, 09:34 AM
  4. [SOLVED] Excel Workspace Save trouble
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2006, 02:55 PM
  5. [SOLVED] How to save excel spreadsheet and word doc with one save
    By CEP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2005, 06:06 PM
  6. [SOLVED] Trouble opening an Excel file that contains macros
    By JohnR in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-08-2005, 04:06 PM
  7. [SOLVED] Save text of spreadsheet--without macros or data query
    By Bryan Dickerson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2005, 10:06 AM

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