+ Reply to Thread
Results 1 to 5 of 5

Error 1004 Document Not Saved .ExportAsFixedFormat xlTypePDF

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Error 1004 Document Not Saved .ExportAsFixedFormat xlTypePDF

    I may have figured it out. The "Location" string was pulling from a dynamic range that sometimes contained ":" or "\" or other offending characters. I've removed these characters from the range and it seems to be working. My code is below:

    Sub SaveClear_Form()
    
        Dim wb As Workbook
        Dim ws As Worksheet
        
            Set wb = ThisWorkbook
            Set ws = wb.Worksheets("Field Application Sheet")
            
        'Set print area
            ws.PageSetup.PrintArea = ws.Range("$G$9:$O$41")
    
            'Delcare variables to get values from form
            Dim appName As String
            Dim appLoc As String
            Dim appWO As String
            Dim appDate As Date
            Dim appTime As Date
                    
                'Get values from form to generate file name
                appName = ws.Range("$H$9").value
                appLoc = ws.Range("$H$13").value
                appWO = ws.Range("$L$10").value
                appDate = ws.Range("$G$35").value
                appTime = ws.Range("$H$35").value
                
            'Delcare file name variable
            Dim pdfName As String
            
                'Generate pdfName
                pdfName = "ChemApp_" & appName & "_" & appLoc & "_" & appWO & "_Date_" & Format(appDate, "m_d_yyyy") & "_Time_" & Format(appTime, "h_mm_AM/PM") & ".pdf"
            
            'Get file path of workbook and append with folder name for pdf records
            Dim path As String
                path = wb.path & "\Chemical Application Records\"
                
            ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & pdfName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
          
    End Sub
    If it works on my coworkers computer I will mark this as solved.
    Last edited by TFiske; 04-20-2018 at 06:30 PM.

  2. #2
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Error 1004 Document Not Saved .ExportAsFixedFormat xlTypePDF

    Yes, that appears to have been the problem. The code is working now and generating a pdf with the dynamic name as intended. I've added the following code to all userform controls related to generating the pdfName string to prevent users from entering special characters into those fields:

    Private Sub controlname_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    
        Select Case KeyAscii
            Case Asc("0") To Asc("9")
            Case Asc("A") To Asc("Z")
            Case Asc("a") To Asc("z")
    Case Asc(" ") To Acs(" ")
    Case Else KeyAscii = 0 End Select End Sub
    I will mark this as solved.
    Last edited by TFiske; 04-20-2018 at 03:36 PM. Reason: Added code to allow spaces

+ 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. [SOLVED] Once successful VBA now elicits Run-time error '1004': Document not saved.
    By Matthew55 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2017, 12:57 PM
  2. [SOLVED] Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)
    By Sophie.Durrant in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2015, 11:16 AM
  3. Run-time error 1004 Document not saved....
    By ey_up in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2014, 04:47 AM
  4. Run-time error '1004': Document Not Saved (while using LockXLS)
    By lottidotti in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-25-2013, 12:14 PM
  5. ExportAsFixedFormat xlTypePDF not giving same results as native PDF export
    By Rick_HpyVly in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2013, 03:32 PM
  6. Excel 2007 : Run Time Error 1004 - Document not saved
    By Villamankh in forum Excel General
    Replies: 2
    Last Post: 12-17-2010, 09:44 AM
  7. Run-time error '1004'; Document not saved - intermittent
    By Kerry in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-15-2005, 07:15 PM

Tags for this Thread

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