Solved

Close PDF created in Excel with VB

Posted on 2014-09-30
2
165 Views
Last Modified: 2014-09-30
Hi Experts,
I have written a script to create 3 pdfs in a workbook.
The good news is that this is working well. The PDFs are being created and saved to the location that I want them to. When they are created I don't want the user to be able to see the PDF after the script has run (as in I want each pdf to be closed).

I'm wondering if / how to do this?
I figure it would be done similarly to the following:
FileNamePDFcatch.Close

But that won't work...

Heres the current script:
Sub PdfCreator()
Dim wb1 As Workbook, wb2 As Workbook
Dim vSheet As Variant, vSheets As Variant
Dim sCatchFile As String
Dim FileNamePDFcatch
Dim FileNamePDFprocess
Dim FileNamePDFA
Dim CopyForm2 As String
'THIS SCRIPT IS CREATING THE EXCEL WORKBOOK THAT NEEDS TO BE SENT TO THE PMO TO ENTER ONTO THE PIPELINE
Set wb1 = ThisWorkbook

Application.DisplayAlerts = False
Application.ScreenUpdating = False

'Add the future names of the PDF (including location) to the cells onth admin sheets - MAY NEED TO UNHIDE?
FileNamePDFcatch = ActiveWorkbook.Path & "\" & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) & " " & Range("CURRENTorf").Value & "catch.pdf"
Range("PDFcatch").Value = FileNamePDFcatch
'Add the future names of the PDF (including location) to the cells onth admin sheets - MAY NEED TO UNHIDE?
FileNamePDFprocess = ActiveWorkbook.Path & "\" & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) & " " & Range("CURRENTorf").Value & " Process.pdf"
Range("PDFprocess").Value = FileNamePDFprocess
'Add the future names of the PDF (including location) to the cells onth admin sheets - MAY NEED TO UNHIDE?
FileNamePDFA = ActiveWorkbook.Path & "\" & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) & " " & Range("CURRENTorf").Value & " A.pdf"
Range("PDFA").Value = FileNamePDFA
       
    'NEED TO MAKE SO THAT THIS IS ONLY VALUES!!! LOCKING CELLS? NOT Needed if PDF... COPY OF ORF THOUGH?
    'Catchment Worksheet
        Sheets("ORF - Catchment").Visible = True
        Sheets("ORF - Catchment").Select
        Sheets("ORF - Catchment").Copy
        'Create the PDF with the filename determined above
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileNamePDFcatch, _
            Quality:=xlQualityStandard, IncludeDocProperties:=False, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
        ActiveWindow.Close
        FileNamePDFcatch.Close
       
        'Process PDF to be created here too!
        wb1.Activate
        Sheets("ORF - Process").Visible = True
        Sheets("ORF - Process").Select
        Sheets("ORF - Process").Copy
       
        'Create the PDF with the filename determined above
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileNamePDFprocess, _
            Quality:=xlQualityStandard, IncludeDocProperties:=False, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
        ActiveWindow.Close

            wb1.Activate
            'Determine if the checklist is required
            If Range("ACHECKLIST").Value = "Checklist IS Required" Then
            'A Checklist to be created here too!
            Sheets("ORF - A Reporting").Visible = True
            Sheets("ORF - A Reporting").Select
            Sheets("ORF - A Reporting").Copy
            'Create the PDF with the filename determined above
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileNamePDFA, _
                Quality:=xlQualityStandard, IncludeDocProperties:=False, _
                IgnorePrintAreas:=False, OpenAfterPublish:=True
            ActiveWindow.Close

            Else
            End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub


Any help appreciated :-)
0
Comment
Question by:martywal
2 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40353920
Hi,

Pls try

            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileNamePDFA, _
                Quality:=xlQualityStandard, IncludeDocProperties:=False, _
                IgnorePrintAreas:=False, OpenAfterPublish:=False


Regards
0
 

Author Closing Comment

by:martywal
ID: 40353922
Thanks for that!

The only change was:

OpenAfterPublish:=False

Thanks again!!!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question