+ Reply to Thread
Results 1 to 8 of 8

Macro that worked for ages stopped working [Very inexperienced user]

  1. #1
    Registered User
    Join Date
    01-05-2021
    Location
    United States
    MS-Off Ver
    10
    Posts
    3

    Question Macro that worked for ages stopped working [Very inexperienced user]

    Good afternoon,

    I have a macro (below) that I use for work often; it takes a specific sheet, copies it into a new file as values only, saves it in a file location, and moves on to the next sheet.

    A piece of the macro is as follows (it repeats ~40 times with different Client names):

    Please Login or Register  to view this content.
    and repeat with the next client in the list. The tabs are ordered and the names match identically. We have used this macro for years. Now when running, I receive the rather generic:

    Run-Time error '1004':
    Method 'SaveAs' of object '_Workbook' failed

    Other queries of this same error haven't proven too useful as everyone seems to use the SaveAs part differently and I'm not terribly experienced with macro syntax to make sense of it and I'm hoping someone here can help. The debug option highlights the following as the issue:

    "F:\Corporate Reports\CLIENT\2020\12.31.20 LB Report - CLIENT.xlsx" _
    , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

    To make this more interesting, after I've run the macro (remember, there are 40ish of the above code chunks, rinse and repeat style), the previous one works (I can open the file and everything) and it fails on the next. Once I've run the macro ~40 times, it then can go all the way through with no errors? It seems to be per workbook though, as we use this style macro in several books and I really don't want to have to run this 40 times every month when I have a new batch to save.
    Last edited by guineawheat; 01-05-2021 at 06:08 PM.

  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
    44,437

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    Maybe permissions on the file/folder location(s)? Or maybe a lack of space on the drive?

    You repeat the code 40 times? Why don't you create a loop?

    You should really avoid selecting objects like sheets and cells. And there seems to be some redundancy ...
    Please Login or Register  to view this content.
    Could probably be just:
    Please Login or Register  to view this content.
    And this:
    Please Login or Register  to view this content.
    Could be just this:
    Please Login or Register  to view this content.
    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
    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
    44,437

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    Oh, and ...

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional.)

  4. #4
    Registered User
    Join Date
    01-05-2021
    Location
    United States
    MS-Off Ver
    10
    Posts
    3

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    I've looked at the permissions, that doesn't seem to be it as far as I can tell. It stopped working for folders I've used previously as well as a new folder I created for 2021 but it inherited the parent permissions. Like I said, once I run the macro and it fails, when I run it again, the sheet it previous failed on saves just fine. I did do that earlier to test it (because I was getting annoyed and just wanted my reports in their damn folders) and yeah, after running it over and over, all the sheets are out in their respective folders like they should be, I just have never had it throw this error before. A month ago it worked just fine.

    As for why we repeat it 40 times, I didn't write the macro, but I believe it's to specify which sheets we're taking out - so there are lots of tabs in the workbook: Summary, data tables, etc, and then about 40ish Sheets that are individual to each Client, so when we add a new client program, we create them their own tab and add them into the macro (since they also have a unique file directory). We only pull out those client sheets, not all the sheets in the workbook and we have a lot of links throughout the workbook so they are all uniquely named.

    I'll definitely look at making the other improvements you mention though, they make sense to me. A lot of things are how they are because someone did them years ago and it worked so it just never got updated.

  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
    44,437

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    Maybe, for some reason, the sheet(s) became bloated. And, maybe now they're not. So, once a bloated file has been overwritten, it makes space.

    Maybe there are a lot of temporary files on the drive that could be cleared down?

    Rather than repeat the code 40 times, it might be an idea to create an array with the Client sheets and loop through that. Much easier to maintain. The basic code would never need to change, you just add a new client on to the end of the list.

  6. #6
    Registered User
    Join Date
    01-05-2021
    Location
    United States
    MS-Off Ver
    10
    Posts
    3

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    I'll ask IT to take a look; it wouldn't surprise me if there were. It's a shared company drive and there is a LOT of crap on it.

    Do you know of any resources that could help me learn how to do the array? Obviously, I will also look it up myself but would appreciate any direction you could also provide. I've coded a bit in my past but never VB and I'm never quite sure where to start, just been learning as I go with stuff other people have written.

    Thank you so much for your help already.

  7. #7
    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
    44,437

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    I'll try and put something together as an example tomorrow. Nearly 11:00 pm here

  8. #8
    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
    44,437

    Re: Macro that worked for ages stopped working [Very inexperienced user]

    This is the code to loop through a list of tab names:

    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] My VBA macro has stopped working... Please Help!
    By ahalliwell in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2018, 05:05 AM
  2. [SOLVED] Macro stopped working?
    By AmyV1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-22-2017, 10:23 PM
  3. Macro stopped woring - worked 100's of times before (Hide/unhide)
    By InvalidTxtString in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2016, 03:48 AM
  4. [SOLVED] My CommandButton1 has stopped working in my user form
    By ortmll in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2016, 05:14 PM
  5. [SOLVED] Macro stopped working - please help
    By kellynicolebarrett in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-01-2014, 05:49 AM
  6. Macro Stopped Working
    By andybason in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2012, 01:20 PM
  7. Simple question from inexperienced user!
    By swaldock in forum Excel General
    Replies: 3
    Last Post: 12-02-2010, 02:06 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