As explained in a previous thread, I'm creating a macro to rename Solidworks sheets when saving. I think it might be as convenient for some of you.
I'm almost at the end of my rope! I have only one bellow left.
The principle :
The macro starts when you save (it is contained in the Userform which remains hidden).
If the sheet name contains the word "Sheet", another name is requested.
The macro must check that the name given to the sheet is not empty, and is not the same as another sheet (previous or next).
To check that the name is not empty, no problem, but my problem arises when I have to compare that the name is not identical to that of another sheet. It works for the previous sheets but not always for the following ones. For example, if you propose an empty name and then the name of the next sheet, the inputbox does not restart when it should, until the proposed name is unique. This is because if it doesn't, the macro stops and doesn't rename the sheet.
So my problem must be with the loop.
If someone had the miracle solution it would be great!
I don't know VBA so I can't analyze your code but from an algoritm point of view: at the beginning of the execution, I will create a list of leaves and then I will compare the answer with the content of the list, a list that is updated when the name is validated, and so on for the following sheets.
I will try to proceed differently by using your idea but it seems to me not suitable since we do not know the number of starting sheets. This will make it difficult to store their names if there are many of them.
Yes, it is bellowing at a loop that I pointed out in the comments.
The database should compare the user-proposed Nou_nom_feuille value to the names of already existing sheets (the sheets before and after the one to be renamed).
And it doesn't work in all cases, especially if the sheet with the same name is located after the one to be renamed.
For my part, I also had to reverse the Do Until... Loop en Do... Loop Until because otherwise it wouldn't work.
Now it seems to almost work, let me explain:
- it detects when the sheet contains the word "Leaf".
- he then asks me for another name
- If the name is the same as on another sheet or empty, it will ask me again.
The problem is that when I put a correct name (not empty and different from the name of the other sheets), it marks it (after the second time) but still asks me for a name.
I think there is still a serious problem with the loop, but no matter how hard I try, it's impossible to get rid of...
I thank in advance if there is anyone who has the time and the motivation to try to find where the problem comes from.
In fact I thought that my loop worked (because the Inputbox reappeared when I gave an already existing om) but it is not the case. This is the condition for checking whether the proposed name for the sheet already exists in another sheet that is obsolete. My loop with j doesn't work at all.
Anyway thank you again for your help but I think I'm going to give up there because it doesn't work.
And anyway I can't launch the macro at startup even with the \m method in the shortcut because it doesn't launch the macro that triggers the userform.