<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
I had a lot of trouble with your little macro and I am not sure if
it is because there are Bugs in LO or something else is happening. <br>
<br>
First, I believe that your only stated problem is that you enter
"B7>80") and it comes out as "C13". This is because it is
relative. In other words, what you really need if you want to
reference the cell that contains the special formatting is "A1"
because it pretends that you are dealing with a range and you want
to reference inside that range. <br>
<br>
Oddly, this seems to work if you start empty<br>
<br>
Sub Example<br>
Dim mCond(2) As New com.sun.star.beans.PropertyValue<br>
Dim oEntrys As Variant<br>
Dim oCell as object, oDoc as object, oSheet as object<br>
Dim iLine as integer, iColumn as integer<br>
Dim aColumn(9) as string<br>
<br>
oDoc = ThisComponent<br>
oSheet=oDoc.Sheets.getByName("Sheet1")<br>
'Inspect oSheet.getCellByPosition(1,6).ConditionalFormat<br>
'Exit Sub<br>
<br>
aColumn(0)="A": aColumn(1)="B": aColumn(2)="C": aColumn(3)="D"<br>
aColumn(4)="E": aColumn(5)="F": aColumn(6)="G": aColumn(7)="H"<br>
aColumn(8)="I": aColumn(9)="J"<br>
<br>
For iLine = 6 to 9<br>
For iColumn = 1 to 9<br>
<br>
oCell = oSheet.getCellByPosition(iColumn,iLine)<br>
'Inspect oCell<br>
'oEntrys = oCell.getPropertyValue("ConditionalFormat")<br>
oEntrys = oCell.ConditionalFormat<br>
'Inspect oEntrys<br>
oEntrys.clear()<br>
'Print aColumn(iColumn) & CStr(iLine+1) &
">80"<br>
if iLine mod 2 = 0 then<br>
' this formula start at line 7, first cell B7<br>
' looking at sheet, format menu, conditional format
you will see C13<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) & CStr(iLine+1)
& ">80"<br>
mCond(1).Value = "A1>80"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Good"<br>
oEntrys.addNew(mCond())<br>
oCell.ConditionalFormat = oEntrys<br>
oEntrys.Clear<br>
<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) & CStr(iLine+1)
& ">60"<br>
mCond(1).Value = "A1>60"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Average"<br>
oEntrys.addNew(mCond())<br>
oCell.ConditionalFormat = oEntrys<br>
'Inspect oEntrys.getByIndex(1)<br>
else<br>
' this start at line 8, first cell B8, and in this
case you see C15<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) & CStr(iLine+1)
& ">80"<br>
mCond(1).Value = "A1>80"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Keep"<br>
oEntrys.addNew(mCond())<br>
oCell.ConditionalFormat = oEntrys<br>
oEntrys.Clear()<br>
<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) & CStr(iLine+1)
& "<60"<br>
mCond(1).Value = "A1<60"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Review"<br>
oEntrys.addNew(mCond())<br>
oCell.ConditionalFormat = oEntrys<br>
end if<br>
Next<br>
Next<br>
<br>
End Sub<br>
<br>
If I get the ConditionalFormat property and inspect it, however,
only one conditional object is shown, and I am unable to clear the
existing entries.<br>
<br>
I am a bit stumped!<br>
<br>
<div class="moz-cite-prefix">On 08/26/2013 01:16 PM,
<a class="moz-txt-link-abbreviated" href="mailto:joseramos@bb.com.br">joseramos@bb.com.br</a> wrote:<br>
</div>
<blockquote
cite="mid:OF23D3F6EE.FB881771-ON83257BD3.005EE7DE-83257BD3.005EE7E0@bb.com.br"
type="cite"><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2"><font
face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif"
size="2">Hi fellows and thanks for your attention. </font>
<p><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">First, I
learned VBA with Excel by my self. I have no expertise
programming in any language. For now on, I have to use Calc
as much as Excel.
I'm trying to include conditional format thru a basic
program.
I have to create a spreadsheet with conditional format with
lots of cells. Every cell will have a unique formula.
Everything I found so far, led me to code below. This is a
very short example, not the real one, for better view.</font></p>
<font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2"> </font>
<p><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">The
extrange thing is: the cell reference in the formula gets
totally changed.
To understand what I'm writing about, copy this code and
execute it. Don't forget to change sheet name in code or
just rename your sheet with "Example".
After, go to cell B7 and look at conditional format using
format menu. You will see B7 changed to C13. And at B8, you
will see B7 changed to C15. And you may see any other cell
inserted by this code has the same problem (B7->C13,
C7->D13,B8->C15,C8->D15,...).
I used it at version 3.3.3. Also downloaded version 4.0.3
and the problem still remain.</font></p>
<font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2"> </font>
<p><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">Also
tried use absolute reference. The formula keeps right but
not work in sheet. I have to remove "$" manually. When it
done, works fine.</font></p>
<font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2"> </font>
<p><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">Somebody
know what's happening?</font></p>
<font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2"> </font>
<p><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">I post
this queston at AskLibo in August 7 and nothing so far.<br>
</font></p>
<p><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">For any
help, many thanks...</font></p>
<span><font face="Default Sans
Serif,Verdana,Arial,Helvetica,sans-serif" size="2">
<div>Sub Example<br>
Dim mCond(2) As New com.sun.star.beans.PropertyValue<br>
Dim oEntrys As Variant<br>
Dim oCell as object, oDoc as object, oSheet as object<br>
Dim iLine as integer, iColumn as integer<br>
Dim aColumn(9) as string<br>
<br>
oDoc = ThisComponent<br>
oSheet=oDoc.Sheets.getByName("Example")<br>
<br>
aColumn(0)="A": aColumn(1)="B": aColumn(2)="C":
aColumn(3)="D"<br>
aColumn(4)="E": aColumn(5)="F": aColumn(6)="G":
aColumn(7)="H"<br>
aColumn(8)="I": aColumn(9)="J"<br>
<br>
For iLine = 6 to 9<br>
For iColumn = 1 to 9<br>
oCell =
oSheet.getCellByPosition(iColumn,iLine)<br>
oEntrys =
oCell.getPropertyValue("ConditionalFormat")<br>
oEntrys.clear()<br>
if iLine mod 2 = 0 then<br>
' this formula start at line 7, first cell
B7<br>
' looking at sheet, format menu,
conditional format you will see C13<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) &
iLine+1 & ">80"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Good"<br>
oEntrys.addNew(mCond())<br>
<br>
oCell.setPropertyValue("ConditionalFormat",
oEntrys)<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) &
iLine+1 & ">60"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Average"<br>
oEntrys.addNew(mCond())<br>
<br>
oCell.setPropertyValue("ConditionalFormat",
oEntrys)<br>
else<br>
' this start at line 8, first cell B8, and
in this case you see C15<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) &
iLine+1 & ">80"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Keep"<br>
oEntrys.addNew(mCond())<br>
<br>
oCell.setPropertyValue("ConditionalFormat",
oEntrys)<br>
mCond(0).Name = "Operator"<br>
mCond(0).Value =
com.sun.star.sheet.ConditionOperator.FORMULA<br>
mCond(1).Name = "Formula1"<br>
mCond(1).Value = aColumn(iColumn) &
iLine+1 & "<60"<br>
mCond(2).Name = "StyleName"<br>
mCond(2).Value = "Review"<br>
oEntrys.addNew(mCond())<br>
<br>
oCell.setPropertyValue("ConditionalFormat",
oEntrys)<br>
end if<br>
Next<br>
Next<br>
<br>
End Sub<br>
<br>
<br>
José<b> </b>Ramos<br>
</div>
</font></span></font>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LibreOffice mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LibreOffice@lists.freedesktop.org">LibreOffice@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/mailman/listinfo/libreoffice">http://lists.freedesktop.org/mailman/listinfo/libreoffice</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Andrew Pitonyak
My Macro Document: <a class="moz-txt-link-freetext" href="http://www.pitonyak.org/AndrewMacro.odt">http://www.pitonyak.org/AndrewMacro.odt</a>
Info: <a class="moz-txt-link-freetext" href="http://www.pitonyak.org/oo.php">http://www.pitonyak.org/oo.php</a>
</pre>
</body>
</html>