Solved

Close PDF created in Excel with VB

Posted on 2014-09-30
2
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

724 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