Page Number on Calc Footer via Macro

I have looked every where for days and I didn’t find out how (via macro) to insert page number in right footer in a custom page style on Calc.
Would Anybody know it?

Out of curiosity: Why do you think to need this?

Everything I do, I do think the one that will use my program…I don´t want that he needs “to go to that menu”, “to go to this option”. Everything has to be automated. I don’t want that Anyone has headache by using my program.

Sorry…I have just found this…

Dim oDoc As Object
oDoc = ThisComponent
oPageStyles = oDoc.StyleFamilies.getByName(“PageStyles”)
oDefault = oPageStyles.getByName(“MyStyle”)
oDefault.FooterIsOn = true
oFooter = oDefault.RightPageFooterContent
oFooter.RightText.String = “”
oDefault.RightPageFooterContent = oFooter
oPageNumber = oDoc.createInstance(“com.sun.star.text.TextField.PageNumber”)
oTextCursor = oFooter.RightText.createTextCursor
oTextCursor.gotoEnd (False)
oTextCursor.String = “Page”
oTextCursor.gotoEnd (False)
oFooter.RightText.insertTextContent (oTextCursor, oPageNumber, True)
oPageCount = oDoc.createInstance (“com.sun.star.text.TextField.PageCount”)
oTextCursor.gotoEnd (False)
oTextCursor.String = " of "
oTextCursor.gotoEnd (False)
oFooter.RightText.insertTextContent(oTextCursor, oPageCount, true)
oDefault.RightPageFooterContent = oFooter