+ Reply to Thread
Results 1 to 6 of 6

Workbook SaveAs using Input Box to name file gives Error 1004

  1. #1
    Registered User
    Join Date
    08-30-2017
    Location
    SHEFFIELD,ENGLAND
    MS-Off Ver
    2016
    Posts
    37

    Workbook SaveAs using Input Box to name file gives Error 1004

    Hi,

    This may sound a stupid question but I am struggling to make this piece of code to suit my requirement

    The objective

    I require a macro assigned to a command button on a userform that when pressed will save the active workbook to a directory (the directory is hardcode in) and the user uses an input box to name the file. Simple right ?

    Maybe its that Friday feeling but as simple as this may seem I haven't been able to find a solution

    This is what I have managed to muster so far

    Please Login or Register  to view this content.
    The code runs put fails on the:-

    Run-time error '1004'
    Method 'SaveAs' of object'_workbook' failed


    Any ideas guys ?

    Thanks


    Slosh

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,789

    Re: Workbook Save As using Input Box to name file

    This code works for me when I use a path that exists on my machine. I suspect that your path doesn't exist on your machine. Copy the path from your code and paste into the Windows Explorer folder box and see what you get.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    08-30-2017
    Location
    SHEFFIELD,ENGLAND
    MS-Off Ver
    2016
    Posts
    37

    Re: Workbook SaveAs using Input Box to name file gives Error 1004

    Hi Jeff,

    The path exists fine, I doubled checked that before handwriting it into the code.

    Basically I have a master workbook which I don't want to overwrite. A user will input data into the relevant sheets using a VBA Userform then save the workbook as a new name file. Predominately using the current date as the file name format (hence the input box requirement). This is executed by using a command button on the Userform. I'm controlling all workbook functions via the Userform.

    Alternatively, if there is somehow a way this could be hard written into the code to remove the need for an input box and save to the designated directory, then this will suffice as well.

    Slosh

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,789

    Re: Workbook SaveAs using Input Box to name file gives Error 1004

    To use the current date as a file name:

    Please Login or Register  to view this content.
    However, that doesn't address the error. It didn't occur to me that you might be typing illegal characters into the input box. If you are typing "5/10/2018" then that will cause an error because "/" is not allowed as a file name character and will cause VBA to look for a folder under Data called 5\10 which of course does not exist.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Workbook SaveAs using Input Box to name file gives Error 1004

    Id always use time as well as especially when setting up errors can occur if the filename exists
    Please Login or Register  to view this content.

  6. #6
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Workbook SaveAs using Input Box to name file gives Error 1004

    Try

    Please Login or Register  to view this content.

+ 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] Auto SaveAs Error 1004 - File could not be accessed
    By Trompie in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-06-2018, 07:00 PM
  2. [SOLVED] Runtime error 1004 with my saveas code
    By Anto_BT in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-26-2015, 11:49 AM
  3. [SOLVED] SaveAs 1004 Error
    By Stevo56 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2014, 11:14 AM
  4. SaveAs Error 1004 when replacing
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2013, 10:39 AM
  5. getting run time error 424 or 1004 when using Saveas method
    By Anchal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-12-2013, 03:37 AM
  6. Replies: 4
    Last Post: 05-04-2006, 08:00 AM
  7. error 1004 Method SaveAs of Workbook failed
    By Maury Markowitz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2005, 04:05 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