good evening from Belgium, my first steps on this forum, and…well…I’m stumped…
I cant seem to find the setup to have a macro triggered every time a sheet gets loaded.
Its used to initialize some sheet parameters.
I have managed to get the thing working one one sheet, so I need to duplicate all the trigger connections for every sheet, if I want it working on all sheets, which is not the best in class solution.
Anyone feel like helping me on this matter?
Thanks upfront
Jake
LibO version, OS?
What do you actually want to achieve?
Which document events did you use and in what order when you got “partial success”?
Attach an example .ods containing the code you already tried (as plain text e.g.)
= = =
My example which I use every day (in a preliminary version for years now):
disask_132716_document_events_example.ods (69.6 KB)
(The code is raw and not thoroughly documented.)
tnx for reply, my bad, should have included crucial info…
OS win 11
2026-02-28_231028.pdf (46.6 KB)
LO version
2026-02-28_231316.pdf (89.1 KB)
this works on a single sheet
option explicit
globalscope Sub Macro3
Dim Doc as object
Dim Sht as object
Dim Columns as object
Dim activnum as long
Dim thissht as object
Dim Ocell as object
dim doc as object
dim sheet as object
Sub Main
End Sub
Sub Macro3
’ wait 1000
’ Doc = Thiscomponent
thissht = Thiscomponent.CurrentController.ActiveSheet
’ msgbox thissht.name
activnum = thissht.RangeAddress.Sheet
Sht = thiscomponent.sheets(activnum)
’ Msgbox Sht.Columns(0).Width
If Sht.Columns(0).Width <> 0 then
Sht.Columns(9).Width = 1200 'J
Sht.Columns(8).Width = 2000 'I
Sht.Columns(7).Width = 1200 'H
Sht.Columns(6).Width = 2000 'G
Sht.Columns(5).Width = 1280 'F
Sht.Columns(4).Width = 1930 'E
Sht.Columns(3).Width = 1200 'D
Sht.Columns(2).Width = 2000 'C
Sht.Columns(1).Width = 1200 'B
Sht.Columns(0).Width = 1900 'A
endif
’ if thissht.Name = “TEST” then
Sht.getCellRangeByName("A1").CharWeight = com.sun.star.awt.FontWeight.BOLD
Sht.getCellRangeByName("B4:B38").HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
Sht.getCellRangeByName("F4:F38").HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
’ msgbox thissht.Name
’ endif
End Sub
if I want it working on another sheet in the same workbook, I need to connect the sheet event sheet loaded to that macro…
the code needs some beauty fixes when all works, hehe 
this helps you a bit to de-cypher my problem
tnx again, Jake
(I’m a bit tired now.)
- Why two
.pdfinstead of one.ods? An .ods would exemplify the tried proceeding, and could also contain the additional information. - What events did you actually use?
- If you want sheets with specifically set column widths: Why don’t you create the document using a template containig what you need?
- Again: What do you actually want to achieve?
How do you “load a sheet”? (I don’t know how to do such a thing.)
ok, rest is for tomorrow
sleepwel