+ Reply to Thread
Results 1 to 6 of 6

Thread: [SOLVED]Run-time Error'1004'

  1. #1
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    41

    [SOLVED]Run-time Error'1004'

    Hello,
    I have this script to save a file from a sheet.
    I have a button and when I press it I get the filename correctly but when I press "SAVE" everything stops with this message:
    Run-Time error '1004':
    Method 'SaveAs' of object '_Workboob' failed.
    I have no idea what to do!!!!


    Any advice?

    Thanks
    R



    In debug I get yellow at:
                   wb.SaveAs Filename:=FileSaveName, _
     ---->                                  FileFormat:=NewFileFormat
    
    Sub SaveAsNewFile()
        Dim wb As Workbook
        Dim NewFileName As String
        Dim NewFileFilter As String
        Dim myTitle As String
        Dim FileSaveName As Variant
        Dim NewFileFormat As Long
        
    Set wb = ThisWorkbook
     NewFileName = wb.Sheets("Invoice").Range("B8").Value & "_" & wb.Sheets("Invoice").Range("A16").Value & "#" & wb.Sheets("Invoice").Range("b13").Value & wb.Sheets("Invoice").Range("C13").Value & "_" & wb.Sheets("Invoice").Range("f16").Value & ".xlsm"
          NewFileFilter = "Excel Macro-Enabled workbook (*.xlsm), *.xlsm"
    myTitle = "Navigate to the required folder"
    FileSaveName = Application.GetSaveAsFilename _
                (InitialFileName:=NewFileName, _
                 FileFilter:=NewFileFilter, _
                 Title:=myTitle)
        If Not FileSaveName = False Then
          wb.SaveAs Filename:=FileSaveName, _
                        FileFormat:=NewFileFormat
        Else
          MsgBox "File NOT Saved. User cancelled the Save."
        End If
    
    End Sub
    Last edited by Rober; 02-20-2012 at 06:29 PM. Reason: Solved!

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    6,566

    Re: Run-time Error'1004'

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    With 15 posts you should by now realise this requirement.

    Regards
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    213

    Re: Run-time Error'1004'

    Rober

    Please edit the tags (add [ code ] and [ / code ] no spaces).

    To answer your question - you haven't set NewFileFormat to anything (i.e. it is Empty). Either delete the statement (so Excel defaults to xlsx) or set it to something.

    Cheers, Rob.

  4. #4
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Run-time Error'1004'

    sorry sorry sorry sorry...my ignorance...I hope I did it right

  5. #5
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Run-time Error'1004'

    Yes, I just cecked and I was missing that.

    However how can I specify that I want to make it as pdf? I have pdf acrobat as 'printer', but the default printer is my normal printer.....
    instead of xl?
    R


    Quote Originally Posted by rscsmith View Post
    Rober

    Please edit the tags (add [ code ] and [ / code ] no spaces).

    To answer your question - you haven't set NewFileFormat to anything (i.e. it is Empty). Either delete the statement (so Excel defaults to xlsx) or set it to something.

    Cheers, Rob.
    Last edited by Rober; 02-09-2012 at 07:39 PM.

  6. #6
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    213

    Re: Run-time Error'1004'

    After a bit of Googling...

    
    Sub Print_PDF()
         
        'Check Reference to Acrobat Distiller in the Visual Basic Editor, Tools, References.
                
        Dim PSFile As String, PDFFile As String, pdPDF As PdfDistiller, logFile As String
        PSFile = "c:\Test.ps"
        PDFFile = "c:\Test.pdf"
        logFile = "c:\Test.log"
        Set pdPDF = New PdfDistiller
    
    'Create PS File.
        ActiveWindow.SelectedSheets.PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
        PrintToFile:=True, Collate:=True, PrToFilename:=PSFile
    
        'Convert the postscript file to .pdf
        pdPDF.FileToPDF PSFile, PDFFile, ""
    
    'Delete PS File
    Kill PSFile
    Kill logFile
    End Sub
    Note the requirement to reference Adobe Distiller in the VBE, under Tools, References.

    Cheers, Rob.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0