Renaming Tabs in a spreadsheet in bulk.

Hi Drew :slight_smile:
Thanks for that.  Some of it even makes sense to me.  It looks completely different from the excel one.  A fresh re-write rather than a translation.  I'm hoping that a few more of these real-world examples will help me make sense of the various guides on macros someday.
Thanks and regards from
Tom :slight_smile:

Am 03.02.2012 21:18, Dan Lewis wrote:

      Might there be another method? I just unzipped a Calc spreadsheet.
Then I looked at the Context.xml. I found:
"<table:table table:name =" (tab name) .
  Could this help some?

--Dan

Well, for someone who loves when others write free code, using a text editor is totally inacceptable.
A double-click on the sheet tab is too much, same with Alt-click on the sheet tab since you have to type the sheet name. All this is too cumbersome for today's computer wimps. During the hours they beg for code snippets they could rename thousands of sheets manually.
Now he has plonked me, I hope that he will not notice the following snippet which does a better job for hundreds of sheets starting at the active one.

Sub NameMonthSheets()
REM you may modify the following format string for the sheet names:
Const cOutFormat = "YYYY-MMM"

sm = InputBox("Starting with the active sheet, subsequent sheets will be renamed to months like """& _
format(Now(),cOutFormat)&""""& chr(10)& _
"Please enter the start month as 2 numbers with a dash (YYYY-MM)","macro RenameMonthSheets()", _
format(Now(),"YYYY-MM")
on error goto noInputErr
  dStart = cdate(sm &"-01")
on error goto 0
im = Month(dStart)
iy = Year(dStart)
ish = ThisComponent.CurrentController.ActiveSheet.RangeAddress.Sheet
for i = ish to ThisComponent.Sheets.getCount()-1
  x = im mod 12
  if x = 0 then
    x =12
  elseif (x = 1)and(i > ish) then
    iy = iy +1
  endif
  With ThisComponent.Sheets.getByIndex(i)
    .setName(format(cDate(iy &"-"& x &"-01"),cOutFormat))
  end with
  im = im +1
next
noInputErr:
End Sub