Consulting

Results 1 to 3 of 3

Thread: VBA - Export as PDF and overwrite existing PDFs

  1. #1
    VBAX Regular
    Joined
    Jan 2017
    Location
    Warsaw
    Posts
    70
    Location

    VBA - Export as PDF and overwrite existing PDFs

    Hey guys!

    I am trying to implement an approach which creates an PDF in an defined folder.
    The objective is to replace the existing PDF with the new one.
    How is this possible?

    My current approach looks like this:

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)Worksheets("TblOne").ExportAsFixedFormat Type:=xlTypePDF FileName:="Draft.pdf" Quality:=xlQualityStandardEnd Sub
    

    Does anyone have an idea?


    Best regards
    Josh

  2. #2
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    vFile = "c:\temp\Draft.pdf" 
    killFile vFile
    Worksheets("TblOne").ExportAsFixedFormat Type:=xlTypePDF FileName:=vFile  Quality:=xlQualityStandard
    
    
    Public Sub KillFile(ByVal pvFile)
    Dim FSO
    On Error Resume Next
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.DeleteFile pvFile
    Set FSO = Nothing
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jan 2017
    Location
    Warsaw
    Posts
    70
    Location
    Many thanks!

    But how can I implement your approach?
    The whole code in "Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)"
    Or are these two seperate procedures?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •