Results 1 to 3 of 3

VBA Print PDF Code troubles

Threaded View

  1. #1
    Registered User
    Join Date
    12-31-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2013
    Posts
    9

    VBA Print PDF Code troubles

    Hi Guys,

    I have some buttons on my excel sheet that print my workbook. Ive recently added pdf printing to that list.

    I would like it to check if the pdf file exists, save pdf if it does not. Message box [Yes, No, Cancel] if it does exist, Yes: creates pdf, No: prompts SaveAs dialog, Cancel: ends without Pdf changes . It "almost" works.

    PROBLEM: If there is no PDF there it does not detect this. It always comes up with the dialog box.

    Guessing my learner skills are not what i think they are. (read: basterdise other people's code from online)

    Thanks for the help

    Dim WorkbookName As String
    WorkbookName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
    
    If ActiveWorkbook.Path & "\" & WorkbookName & ".pdf" = "" Then
                ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False, _
                Filename:= _
        ActiveWorkbook.Path & "\" & WorkbookName & ".pdf"
            Else
                Select Case MsgBox("This file exists. Continue & overwrite? No to SaveAs", vbYesNoCancel, "PDF Creation")
            Case vbYes
                        ActiveSheet.ExportAsFixedFormat _
                    Type:=xlTypePDF, _
                    Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, _
                    IgnorePrintAreas:=False, _
                    OpenAfterPublish:=False, _
                    Filename:= _
                ActiveWorkbook.Path & "\" & WorkbookName & ".pdf"
                
            Case vbNo
                Dim bFileSaveAs As Boolean
        bFileSaveAs = Application.GetSaveAsFilename(InitialFileName:=ActiveWorkbook.Name, fileFilter:="PDF (*.pdf), *.pdf")
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=bFileSaveAs
            
            Case vbCancel
            Exit Sub
            End Select
    End If
    Last edited by jonnyking; 01-16-2015 at 08:13 PM. Reason: Removed .xml extension appearing on pdf

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Code troubles - Trying to copy a row to another sheet based on criteria, then delete
    By kurt1985 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-21-2014, 10:48 AM
  2. Code and Formula to print dynamic print area ranges
    By stpeter in forum Excel General
    Replies: 1
    Last Post: 10-15-2013, 03:33 PM
  3. [SOLVED] Need ‘Set Print Area’ Code for Dynamic Print Range based on Conditions
    By dosbirn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2013, 12:13 PM
  4. [SOLVED] Print array code for a series of pages that will also determine print area required?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2012, 11:46 PM
  5. Code Troubles
    By merritts in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-27-2006, 02:17 PM

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