Consulting

Results 1 to 4 of 4

Thread: PDF from a macro in excel

  1. #1

    PDF from a macro in excel

    Hi all,

    I have created a macro to PDF a hidden page using a macro, but i want to use cells within the workbook to save the pdf in the correct location and with the correct title, i have tried this code but it seems to crash on the file name lien every time.

    i have attached my code for the reference.

    Thanks in advance.

    Sub Macro4()' Macro4 Macro
    
    
    ProjectRootFolder = Sheets("RootFolder").Range("B5").Value
    JobNumber = Sheets("Summary").Range("CJobNumber").Value
    CSiteName = Sheets("Summary").Range("CSiteName").Value
    CCompanyName = Sheets("Summary").Range("CCompanyName").Value
    CVaritationNumber1 = Sheets("Summary").Range("CVaritationNumber1").Value
    
    
        Range("AB49:AD49").Select
        ActiveCell.FormulaR1C1 = "PDF Quote 1"
        Sheets("Variation Quote 1").Visible = True
        Sheets("Variation Quote 1").Select
        Range("A1:K62").Select
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
        ProjectRootFolder \ CCompanyName \ JobNumber & " " & CSiteName \ CVaritationNumber1.pdf _
            , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=True
        Sheets("Variation Quote 1").Visible = False
        Sheets("Summary").Se

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
        With Sheets("Variation Quote 1")
        
            .Range("AB49").Value = "PDF Quote 1"
            .Visible = True
            .ExportAsFixedFormat Type:=xlTypePDF, _
                                 Filename:=ProjectRootFolder & Application.PathSeparator & _
                                           CCompanyName & Application.PathSeparator & _
                                           JobNumber & " " & CSiteName & Application.PathSeparator & _
                                           CVaritationNumber1 & ".pdf", _
                                           Quality:=xlQualityStandard, _
                                           IncludeDocProperties:=True, _
                                           IgnorePrintAreas:=False, _
                                           OpenAfterPublish:=True
            .Visible = False
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I'm thinking you're missing some &'s and quotes


        msgbox        ProjectRootFolder & "\" & CCompanyName & "\" & JobNumber & " " & CSiteName & "\" &  CVaritationNumber1.pdf
    
       ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
           ProjectRootFolder & "\" & CCompanyName & "\" & JobNumber & " " & CSiteName & "\" &  CVaritationNumber1.pdf _
            , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=True
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Thank you both!

    a mixture of both codes and i got it working perfectly.

Posting Permissions

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