Ask Your Question

macro to remove bold from a particular range in all sheets

asked 2015-05-27 07:46:24 +0200

jamadagni gravatar image

updated 2015-08-26 20:29:18 +0200

Alex Kemp gravatar image

Hello. I am trying to write a macro using LibO 4.4.3 on Linux 64 bit.

In the 14th column of all sheets, from rows 4 to 45, it should make only the cells with content "अमावास्या" and "पौर्णमासी" bold and remove bold from all other cells. However, I am totally stumped as to how to access the font etc attributes from BASIC. Please help!

This is my attempt going as far as getting the requisite cell object but after that I'm at a loss:

sub boldenPurniAma
    sheets = ThisComponent.Sheets
    for each sheet in sheets
        for row = 4 to 45
            c = sheet.getCellByPosition(14,row)
            ' what should I do here?
        next row
    next sheet
end sub


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-27 08:41:41 +0200

pierre-yves samyn gravatar image

updated 2015-05-27 08:49:02 +0200

Hi - Something like this:

sub boldenPurniAma

dim oSheets as object, oSheet as object, oCell as object
dim lRow as long

oSheets = ThisComponent.Sheets

for each oSheet in oSheets

' Beware, lines/cols are numbered from zero'

    for lRow = 3 to 44
        oCell = oSheet.getCellByPosition(13, lRow)        
        oCell.charWeight =
    next lRow

next oSheet

end sub

See documentation here and here

But you can simply do:

sub boldenPurniAma2

dim oSheets as object, oSheet as object, oRange as object

oSheets = ThisComponent.Sheets

for each oSheet in oSheets

' Beware, the lines are numbered from zero'

        oRange = oSheet.getCellRangeByPosition(13, 4, 13, 44)        
        oRange.charWeight =

next oSheet

end sub


edit flag offensive delete link more


Hi thanks a lot for your kind reply! I agree that the reference lists the properties you mention but I searched a lot and wasn't sure where to refer to if I just, say, wanted to know what members a cell has, or a cell range has for that matter. Can you clarify that?

Note that I still need to know how to identify the text content of a cell based on which I have to make it bold (the second part of my question).

jamadagni gravatar imagejamadagni ( 2015-05-27 09:28:27 +0200 )edit

Sorry I missed that part of the question. This wiki page includes links to various resources including guides and Xray tool that I use.

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-05-27 10:06:49 +0200 )edit

I now tried your solution (and thanks for the ref to Xray). But it does not work as desired. The cell font attribute is indeed changed, but my font comes in regular weight only and the bold is a faux-bold which apparently cannot be enabled by setting the charWeight. Any idea how to set faux bold?

jamadagni gravatar imagejamadagni ( 2015-05-27 15:06:48 +0200 )edit

Sorry, I do not know what it is. Maybe is it just the font that is bold by default: e.g. Segoe UI Semibold, Arial Black, Impact...

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-05-27 15:23:06 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-05-27 07:46:24 +0200

Seen: 1,022 times

Last updated: May 27 '15