Solved

Close PDF created in Excel with VB

Posted on 2014-09-30
2
162 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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn the different options available in the Backstage view in Excel 2013.
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 …

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now