Rename MEP Sheets Loop Verification

Hello

 

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!

 

Thank you!

 

 

Sbier

 


renommer_onglets_popup_enregistrement_-_copie.swp

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.

Thank you stefbeno.

 

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.

 

If a VBA connoisseur had time to take a look. ;)

Hi, can you put your code in a txt file please? (No SolidWorks available)

And does the macro bug in a particular place?

Otherwise you put spies on the different variables for where it was blocking?

Hello 

You will find attached the text of my macro.

 

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.


macro_copie.txt

Hello

 

No idea where the problem comes from?

 

Thank you in advance,

1 Like

In fact, in my opinion your line:

And Nouveau_nom_feuille <> ""

should be rather:

OR (Nouveau_nom_feuille = "")

Because if the name IS empty OR if the name IS the same as another, you have to restart your inputbox, right?

 

 

 

Hello!

 

Meric for correcting this mistake!

 

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.


macro_copie_v2.txt

It's normal for it to ask you twice , that's how it is in your code!

We should remove the first one (comment it with an apostrophe to test):

Nouveau_nom_feuille = InputBox(....

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.

Ok  too bad!

If I helped, please choose one of my answers by clicking below "mark this answer as the best answer", it allows me to earn a few points!

Thank you, have a good day.