Libre Office Writer macro to conditionally change font color - libreoffice-basic

I am on Libre Office 6.0. I generated a macro to change the font color of selected text to 'Blue 3'. It works fine.
What I want the macro to do is select the entire document and change the font color to 'Blue 3' for any blue text that is some other color of blue.
The issue is that I converted some documents and the hyperlinks are blue but an off-color of blue. Highlighting and correcting multiple hyperlinks surrounded by black text is a laborious process.
sub ChangeToBlue3
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Color"
args1(0).Value = 255
dispatcher.executeDispatch(document, ".uno:Color", "", 0, args1())
end sub

Related

Set the theme header font for text in a shape

I develop a VBA add-in for PowerPoint which can insert a table into a slide. I set the font family for the table's header cells to the ones defined in the theme fonts. I want it to change when I switch to another theme font.
However, if I use the following code the font will be "pinned" to the font family name of the theme's major font and does not change when I change the theme fonts.
Sub FormatTable(table As table)
Dim headerFont As ThemeFont
Set headerFont = ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MajorFont(1)
For Each c In table.Rows(1).Cells
c.shape.TextFrame.TextRange.Font.Name = headerFont.Name
Next c
End Sub
How do I have to rewrite the code to keep the font exchangeable via theme changes?
' Theme fonts have special names
'Body font, Latin (ie main) +mn-lt
'Heading Font, Latin + mj - lt
'Body Font, Eastern + mn - ea
'Heading Font, Eastern + mj - ea
'Body font, complex scripts +mn-cs
'Heading font, complex scripts +mn-cs
Sub FormatTable(table As table)
Dim headerFont As ThemeFont
Dim c As Cell
Set headerFont = ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MajorFont(1)
For Each c In table.Rows(1).Cells
' This sets the font to whatever the NAME of the theme font is
' c.Shape.TextFrame.TextRange.Font.Name = headerFont.Name
' This sets it to the actual theme font:
c.Shape.TextFrame.TextRange.Font.Name = "+mn-lt"
' And after running the code, you'll see that the font
' is set to e.g. Calibri (Body) rather than just Calibri
Next c
End Sub

How change the background color in a Word doc?

I wanted to know how can I change the background color of the text in Word on all my doc. For exemple I got some text with blue/red/pink background color and I want that the bg color of all my doc white.
I got and exemple for the font color :
Sub color()
'
' color Macro
'
'
Dim Plage As Object, Wrd As Object
Set Plage = ActiveDocument.Content.Words
For Each Wrd In Plage
If Wrd.Font.color = RGB(0, 0, 255) Then _
Wrd.Font.color = RGB(128, 128, 128)
Next Wrd
End Sub
But I don't know how to apply this VBA code for the background color.
Maybe with Document.Background property ?
There are three background color settings you have to deal with:
You can have text marked with a Text Highlight. This can be modified with Range.HighlightColorIndex. To remove the highlight, use wdNoHighlight
You can have Shading. Shading is set on paragraph level can can be modified with Range.Shading.BackgroundPatternColor. To remove it, use wdColorAutomatic
You can have set the background color of a whole document. This can be modified using Background.Fill of the document. Either set the ForeColor to white, or set the visible-property to false.
To clean everything at once, use something like this:
Sub RemoveBackgroundColor()
With ActiveDocument.Content
.HighlightColorIndex = wdNoHighlight
.Shading.BackgroundPatternColor = wdColorAutomatic
End With
ActiveDocument.Background.Fill.Visible = msoFalse
End Sub

How to change text colour when text box clicked in Macro enabled Powerpoint 2013?

So I would like the text to change colour from grey to black... How do I do this on Powerpoint 2013 and where would I apply the code? Sorry in advance for not supplying any code I just don't know where to start.
I figured it out myself...
NOTE: You have to set the ForeColor to a certain color before you begin the Slideshow Presentation.
This example shows how to change the preset color to black
Private Sub TextBox1_GotFocus()
TextBox1.ForeColor = RGB(0, 0, 0)
End Sub
.

Word VSTO - Filling a shape does not work in Word 2010 and Word 2013?

I use the following VB.NET (VSTO) code to add a shape in MS-Word,
Dim app As Word.Application = Globals.ThisAddIn.Application
Dim doc As Word.Document = app.ActiveDocument
Dim left As Single = CSng(Convert.ToDouble(app.Selection.Information(Word.WdInformation.wdHorizontalPositionRelativeToPage)))
Dim top As Single = CSng(Convert.ToDouble(app.Selection.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)))
Dim shape As Word.Shape = doc.Shapes.AddShape(1, left, top, 225.1F, 224.5F)
shape.Fill.BackColor.RGB = ColorTranslator.ToOle(Color.Transparent)
shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
shape.Fill.Transparency = 0.0F
shape.Line.Transparency = 0.0F
shape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
shape.Fill.UserPicture("C:\Newfolder\App1.jpg")
What this code does is, it adds a rectangle shape at cursor point, makes it transparent (both background and line) and adds (fills) an image.
This works fine in Word 2007. But on Word 2010 and Word 2013 there is an issue. It adds the rectangle shape at cursor point and makes it transparent. But it does not fill the image.
shape.Fill.UserPicture("C:\Newfolder\App1.jpg")
The above line of code does not work in Word 2010 and Word 2013. Other parts works fine. How to modify the code to fill the image in the rectangle shape in Word 2010 and 2013?
Instead of shape.Fill.UserPicture("C:\Newfolder\App1.jpg") try
Word.Range range = shape1.TextFrame.TextRange;
range.InlineShapes.AddPicture(#"C:\Newfolder\App1.jpg", false, true, Type.Missing);

Get Font Size List in Powerpoint VBA

This code prints out every entry in the Font Size list combo box in Excel 2007 :
Sub FontSizeList()
Dim combo As CommandBarComboBox
Dim i As Integer
Dim j As Integer
For i = 1 To Application.CommandBars("Formatting").Controls.Count
If Application.CommandBars("Formatting").Controls(i).Caption = "&Font Size:" Then
Set ctl = Application.CommandBars("Formatting").Controls(i)
For j = 1 To ctl.ListCount
Debug.Print ctl.List(j)
Next j
End If
Next i
End Sub
However, when I run the same code in Powerpoint 2007 the List is Empty? How can I intialize the Font Size combo box in Powerpoint VBA? I have checked both Font Size properties 'Visible' and 'Enabled', and they are both set to True.
Thanks very much
Joe
I've tried your code on both Excel and PowerPoint 2007.
On PowerPoint, FontList and FontSize are unselectable (dark grey) if no text bloc (or drawing) is selected. That could explain why the ListCount is still 0 when debugging.
That could also explain why it does work on PPT 2003 because you do not have the ribbon and maybe FontSize and FontList are already selected.
Unfortunately, even while selecting a bloc text, i did not manage to have a ListCount > 0. I'd have to look at it further.
Max