+ Reply to Thread
Results 1 to 5 of 5

How to make excel file auto save to PDF office 2010

Hybrid View

  1. #1
    Forum Contributor sspreyer's Avatar
    Join Date
    07-05-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    180

    How to make excel file auto save to PDF office 2010

    Hi everyone
    I have workbook I would like to auto save to PDF copy file in different location every time the original file is save maybe some VBA code is this possible ???

    Thanks in advance

    Shane
    Last edited by sspreyer; 08-16-2013 at 04:17 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to make excel file auto save to PDF office 2010

    Hello Shane,

    Add this macro to your ThisWorkbook module. Change the file path and name to what you will be using.
    Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    
        Dim Filename As String
        Dim Filepath As String
        
            Filepath = "C:\Users\Owner\Documents\"
            Filename = Filepath & ThisWorkbook.Name
    
            If Success Then
                With ThisWorkbook.ExportAsFixedFormat _
                    (Type:=xlTypePDF, _
                     Filename:=Filename, _
                     Quality:=xlQualityStandard, _
                     IncludeDocProperties:=True, _
                     IgnorePrintAreas:=True, _
                     OpenAfterPublish:=False)
                End With
            End If
            
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor sspreyer's Avatar
    Join Date
    07-05-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: How to make excel file auto save to PDF office 2010

    hi thanks for your help i seem to be get error with this code i have highlighted in the code showing were it say's im getting compile error also having trouble entering a file name to work

    cheers
    p.s sorry for being a pain

    Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    
        Dim Filename As String
        Dim Filepath As String
        
            Filepath = "C:\Users\Shane\Documents\"
            Filename = Filepath & ThisWorkbook.Name
    
            If Success Then
                With ThisWorkbook.ExportAsFixedFormat _ ' this line highlights and i get error message ("compile error expected file or variable")
                    (Type:=xlTypePDF, _
                     Filename:=Filename, _
                     Quality:=xlQualityStandard, _
                     IncludeDocProperties:=True, _
                     IgnorePrintAreas:=True, _
                     OpenAfterPublish:=False)
                End With
            End If
            
    End Sub
    Last edited by jeffreybrown; 08-18-2013 at 09:58 AM. Reason: As per Forum Rule #12, please don't quote whole post unless necessary -- it's just clutter.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to make excel file auto save to PDF office 2010

    Hi,

    It works for me if set out as

    
    With ThisWorkbook
            .ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=Filename1, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=True, _
            OpenAfterPublish:=False
        End With
    i.e. without the parentheses either side of the .Export......code and with the .Export.... as a new line
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    07-14-2014
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    2

    Re: How to make excel file auto save to PDF office 2010

    Should be:
    With ThisWorkbook
            .ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=Filename1, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=True, _
            OpenAfterPublish:=False
        End With
    Besides, if you set a print area, make sure to set "IgnorePrintAreas" to "False".

    Last, but not least, I combined some code I found elsewhere with the code in this forum. That way my PDF file saves in the same location as the Excel file without having to set the path, manually. Next to that, the PDF file only contains the print area of the active worksheet, instead of the whole Excel file :

    
    Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    Dim ws As Worksheet
    Dim strPath As String
    Dim myFile As Variant
    Dim strFile As String
    
    Set ws = ActiveSheet
    
    'enter name and select folder for file
    ' start in current workbook folder
    strFile = Replace(ThisWorkbook.Name, ".xlsm", "") _
                & ".pdf"
    strFile = ThisWorkbook.Path & "\" & strFile
    
    If Success Then
        ws.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=strFile, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=False
    
    End If
    
    exitHandler:
        Exit Sub
    End Sub
    
    Last edited by ledenjes; 07-14-2014 at 06:34 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 04-24-2013, 10:16 AM
  2. Disabling auto save in excel 2010
    By Dikar in forum Excel General
    Replies: 1
    Last Post: 10-29-2012, 07:34 AM
  3. VB code to auto save file as excel 2010
    By bryanc2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2010, 01:44 PM
  4. Does Office 2003 Pro Excel have auto-save?
    By ehop in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-03-2005, 12:45 PM
  5. [SOLVED] [SOLVED] Does Office 2003 Pro Excel have auto-save?
    By ehop in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 11-02-2005, 06:17 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1