+ Reply to Thread
Results 1 to 5 of 5

Run Time Error 1004

Hybrid View

  1. #1
    Registered User
    Join Date
    09-29-2024
    Location
    Texas
    MS-Off Ver
    2024
    Posts
    11

    Run Time Error 1004

    Can anyone spot the mistake. It gets as far as opening the new copy of the workbook sheets and that's all. Also, it is naming the new copy "2024.xlsx" instead of "Text (Date -1 mm/dd/yyyy)"

    Worksheets(Array("Sheet 1", "Sheet 2")).Copy
        ActiveWorkbook.SaveAs Filename:="file location removed for safety" & "Text" & Format(Date - 1, "mm/dd/yyyy") & ".xlsx", _
                FileFormat:=xlOpenXMLWorkbook, WriteResPassword:="0000", ReadOnlyRecommended:=True
        ActiveWorkbook.Close

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,099

    Re: Run Time Error 1004

    You can't have slashes ( / ) in a file name. Try changing the format to "mm-dd-yyyy".
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-29-2024
    Location
    Texas
    MS-Off Ver
    2024
    Posts
    11

    Re: Run Time Error 1004

    Thank you! That worked.

    When the new copy opens up it is asking me if I want to save it even though the new copied file already in its correct folder. Is there a way to bypass this popup?

    My macro on the master workbook continues running on the new copy workbook instead of the master workbook. It is not closing the ActiveWorkbook copy. Do you know how to remedy this?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,099

    Re: Run Time Error 1004

    Quote Originally Posted by MattyT92 View Post
    Thank you! That worked.

    When the new copy opens up it is asking me if I want to save it even though the new copied file already in its correct folder. Is there a way to bypass this popup?

    My macro on the master workbook continues running on the new copy workbook instead of the master workbook. It is not closing the ActiveWorkbook copy. Do you know how to remedy this?
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,099

    Re: Run Time Error 1004

    You've added a password and you've said Read Only Recommended. So, you will be asked for the password and you will be asked if you want to make changes.

    Can't see any reason why it would have any issues with the location.

    This line of code, Worksheets(Array("Sheet 1", "Sheet 2")).Copy, creates a new workbook which becomes the Active Workbook.
    This line of code, ActiveWorkbook.SaveAs Filename:="file location removed for safety" & "Text" & Format(Date - 1, "mm-dd-yyyy") & ".xlsx", _
    FileFormat:=xlOpenXMLWorkbook, WriteResPassword:="0000", ReadOnlyRecommended:=True, saves the newly created and active woorkbook
    This line of code, ActiveWorkbook.Close, closes the newly created and active woorkbook

    This then should make the Master workbook active again, all things being equal. Nothing in the code closes the Master workbook.

+ 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] I am getting error as "Run Time error '1004' Microsoft excel cannot paste the data
    By Amittapre in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 03-24-2017, 04:40 PM
  2. [SOLVED] Sort Macro Run-time error '1004': Application/Object-defined error.
    By sam1212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2014, 10:05 AM
  3. Addon error : Run-time error '1004': Method 'MacroOptions' of object '_Application' failed
    By jtcoleman in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 02-05-2014, 12:23 PM
  4. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  5. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  6. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  7. [SOLVED] run-time error '1004': Application-defined or object-deifined error
    By rich5665@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2005, 05:05 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