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
Solved

Close PDF created in Excel with VB

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GFI and SCCM 2012 5 80
Display desktop shortcuts without their graphic icons 7 96
SignTool Error with Windows 10 5 177
Cannot get OneDrive working on Wndows 10 2 56
MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

808 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