If Hidden Sheet is Not Detected,

Hello there,

I have added an invoke VBA code below to detect hidden sheets from a list of excel files and subsequently write into a data table using uipath activities.

However, by applying the current code, it will throw an error once it meets an excel file with no hidden sheets and the workflow stops. The error “Assign: Object reference not set to an instance of an object” appears.

May I ask how should i amend the invoke code or should I add any activity to resolve the error so that those excel files can be processed and indicate in writing (“No hidden sheets detected”) in the data table?

1 Like

how are you calling this vba code? can you post screenshot of your xaml? or upload the xaml?

Hey @WS_Chai

May I know the place of error ?

Invoke VBA ?


1 Like

hey @WS_Chai

its because returnText is NULL if no hidden sheets
you need to initialize returnText to “” first by adding returnText = “”

Dim returnText as string
returnText = ""

so now if theres no hidden sheets returnText will =“” instead of a NULL

1 Like

if ws.Visible = 0 → if ws.Visible is Nothing
change it to this

1 Like

Hey Jack,

Thanks for your rely.
Attached is the screenshot of my workflow.

Workflow.pdf (90.9 KB)

Hi @WS_Chai

please try my answer above

Hi @jack.chan,

Can I confirm if you mean this?
Did I amend correctly?

yes please try that

Hi Jack,

I have tried it, it works well for excel files with no hidden sheet now.

However, for those files with hidden sheets, the wordings of “no hidden sheet detected” appeared before the names of hidden tabs’.

Is there anything that I have done wrongly?

@WS_Chai sorry ignore my previous reply

change to this

Public Function GetHiddenSheet() As String
    Dim returnText as string
    returnText = ""
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Visible = 0 Then
            returnText = returnText + ws.Name + "|"
            'returnText = ""
        End If
    Next ws

     If returnText = "" Then
        returnText = "This EGA does not contain any hidden sheet"
     End If
    GetHiddenSheet = returnText
End Function

@jack.chan ,

There is an error, do you know why?

can you go to task manager and kill all excel processes and then try again?

Hey Jack,

It’s working fine now. Many thanks to your help :smile:

1 Like

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