+ Reply to Thread
Results 1 to 6 of 6

Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    65

    Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

    This is driving me mental

    The code below is supposed to loop through a list of customers on ActiveSummary sheet, copy the account number into G9 on ActiveFrontSheet and then save ActiveFrontSheet as a pdf in a specified file. The file path for the main folder is in ActiveSummary B1 and the subfolder is in ActiveSummary C7 so that I can change the file path if I want to without having to edit the code.

    PHP Code: 
    Sub Print_Active()
        
    Dim ActiveSummary As Worksheet
    Set ActiveSummary 
    Worksheets("ActiveSummary")

    ' Sort ActiveSummery by Customer Name

    With ActiveSummary

    Dim lastrow As Long

    lastrow = .Cells(Rows.Count, 2).End(xlUp).row
    .Range("A10:J" & lastrow).Sort key1:=.Range("B10:B" & lastrow), _
       order1:=xlAscending, Header:=xlNo
       
    End With

    '
    Copy account number and past into ActiveFrontSheet    
        
        Sheets
    ("ActiveSummary").Select
        Range
    ("A10").Select
        Fpath 
    Range("B1").Text Range("C7") & "\"
        
        While ActiveCell.Value > "
    1"
            Selection.Copy
            
            Sheets("
    ActiveFrontSheet").Select
            Range("
    G9").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Application.CutCopyMode = False
     
    ' Build File name and save as .pdf       
            
     Fname = "
    #Front Sheet" & UCase(Range("G12").Value & " (" & Range("G9") & ")")
            
            
    ActiveSheet.ExportAsFixedFormat _
            Type
    :=xlTypePDF_
            Filename
    :=Fpath Fname ".pdf"
                    
            
    Sheets("ActiveSummary").Select
            ActiveCell
    .Offset(10).Select

        Wend

    End Sub 
    When I run the macro it gives me "runtime error 1004: Document not saved. The file may be open, or an error may have been encountered when saving" Debug takes it to here:

    PHP Code: 
            ActiveSheet.ExportAsFixedFormat _
            Type
    :=xlTypePDF_
            Filename
    :=Fpath Fname ".pdf" 
    I have pretty much exactly the same code in a different workbook and it works fine, all i changed when I copied it over to this workbook was the Fname and the Fpath so I don't get why it's not working.

    Can anyone tell me where I'm going wrong please?

    Thanks

    Soph

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

    Hi, I think most probable cause is some special character in the file name or path name, e.g. *, ?. etc.
    try to debug.print, display in msgbox Filename before trying to use it in the ExportAsFixedFormat
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    09-14-2011
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    65

    Re: Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

    Hi, I tried that and the Fname comes up on the msgbox as I wanted it to, ie. "Front Sheet, CUSTOMER NAME (1234)"

    The customer name will never have any special characters that I can think of, it will only ever have a - or &, the code when I was using it in the other sheet always worked fine, even for the instances where the customer name contained - or & so I am properly stumped!

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

    Actually, I advised to check Filename, not just Fname, i.e. Filename has both path and file name in it... If Filename is also OK, I'm not able to think of anything else

  5. #5
    Registered User
    Join Date
    09-14-2011
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    65

    Re: Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

    I worked it out... but am not saying what the problem was because I was being an idiot!

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Runtime Error 1004: Document Not Saved (ExportAsFixedFormat)

    :-) at least the problem is solved

+ 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: 0
    Last Post: 12-16-2014, 10:12 AM
  2. 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
  3. 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
  4. 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
  5. [SOLVED] 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

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