Iterating Macro 1004 error

Paulb1985

New Member
Joined
Jan 5, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I've got a macro that copy-pastes project data from two different sheets into a new sheet, saves this third sheet as a new file, and loops through that same process with the next batch of data (i.e. the next project).
The macro works fine...for 5 files, then it gives a 1004 warning about protected workbooks (see screenshot).
Screenshot 2022-01-05 174206.jpg


This surprised me because a) the macro itself sets a password on the newly created file AFTER doing all the copy-pasting, and b) why would the macro run fine for the first 5 files, and then suddenly stop?

Before posting the entire code, I wondered if there's a generic answer / thing I might have overlooked that causes a macro to run into this error midway through the iteration.

Any thoughts are much appreciated.

Best,

Paul


EDIT:
It may be useful to know that the debugger points me to the line
wbkOut.Close SaveChanges:=True
 
Last edited by a moderator:
Hmm, no there is nothing there that would interfere with anything.

Are you sure that the offending sheet (the one giving you problems) doesn't already have protection on it from the start?
Strange...yes, it does not have any protection to begin with. It's a pity, but thanks anyway for the help. I'll find a work-around without VBA.
Wishing you a good weekend, and thanks for the help!
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top