Can't get first Excel Sheet name

I’m following along academy here.

Here’s what we’re trying to do:
Loop through a few excel files, test the first worksheet in Excel and if it’s not named “Sheet1” then rename it.

We set up an If statement with this condition:

InputFile.SelectedSheet.Name isNot "Sheet1"

And then in the Then statement we rename the spreadsheet to “Sheet1”
I also added a log statement in the Then block to test.

Here’s what’s happening:

  1. The file where the error is is simply adding a NEW spreadsheet called “Sheet1” instead of renaming the original one.
  2. Every single file is logging the error (reached the then statement), which is not supposed to happen.

I followed the tutorial exactly, I believe. What did I do wrong?

Hi @Terry_Marr

Try this way in the meanwhile some screenshots of your process will help me find the error.

Condition used in If:

Excel.SelectedSheet.Name isNot "Sheet1"

Regards

Can you try to use <> instead of isNot because isNot operator is for compare object and not check equality.

InputFile.SelectedSheet.Name <> "Sheet1"

Regards,

Yoichi thanks for responding. I put in the <> in the condition and here’s what’s happening.

  1. The other files with “Sheet1” as the first sheet are now not erroring. They are not caught in the condition.

  2. The erroring file, the one with the first sheet saying “Sales”, is being caught, but instead of renaming that first sheet to “Sheet1” it is creating a NEW sheet and calling that “Sheet1”.

Is there not a command that will take the first sheet (it is also the only sheet) perhaps by the number 0, and rename it to what we want?

Hi Varunraj – I’m new. Can you quickly tell me how you got that screenshot into the post above?

1 Like

Hi @Terry_Marr

Right click on the sequence you will see the option Copy As Image click on that. Paste it wherever you want. You can also save the image by right clicking on the sequence and Click Save As Image.

Regards

Aha! I figured it out! I had put a log message above the condition that tried to show the number of rows for that sheet. It put it in like this:

InputFile.Sheet("Sheet1).RowCount

And since the code didn’t find “Sheet1” there, it sneakily created one. Once I took that activity away, the condition worked correctly

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.