We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

Sheet name vs. sheet index [closed]

asked 2012-04-23 22:59:56 +0200

Max74 gravatar image

Hi there,

I need a macro that check if a sheet exists by its index instead of its name

For example:

oSheets = ThisComponent.Sheets()

If oSheets.hasByName("Invoice") Then


works fine

Instead I need something like this (that obviously doesn't work):

If oSheets.hasByIndex(2) Then


Anyone can help me?


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-15 23:13:20.479575

1 Answer

Sort by » oldest newest most voted

answered 2012-04-25 17:36:02 +0200

w_whalley gravatar image

updated 2012-04-25 17:57:19 +0200

Sub Main
target=2 rem looking for sheet number 2 (not sheet index 2)
i=oSheets.getcount() rem i is the number of sheets
if (i >= target) then
   msgbox "Found it"
   msgbox "Not found"
end if   
End Sub
edit flag offensive delete link more


@Max74, Did @w_whalley's answer work for you? Please let us know so we can resolve this question.

qubit gravatar imagequbit ( 2013-01-27 07:12:09 +0200 )edit

Question Tools


Asked: 2012-04-23 22:59:56 +0200

Seen: 2,536 times

Last updated: Apr 25 '12