Macro cant change color of highlighted text, which is part of a topic text? thx

krsto e. shared this question 58 days ago
Discussion Open

hi,

i dont found a easy way to the "color chooser",

it's 3+ clicks away from me, and i usually only use 3-5 standard colors.

so i think of using macros to set color in my usual colors e.g. red, blue etc.


i asked the magic mirror and that making a macro to turn the whole topic text into red is easy (see bottom),

but in many times, i only want to use red to highlight some text INSIDE a paragraph (all as topic text).


magic mirror say macros cant do that, addon can.

is it?

thanks.


ps: code for macro to turn the whole topic's text into a set color e.g. red.

one could duplicate for each color and set different hotkey with that. not too useful, there is a KB shortcut for set font color, however just i work with several colors.


Sub Main
    ChangeSelectedTopicTextColorToRed
End Sub

Sub ChangeSelectedTopicTextColorToRed()
    Dim app As Object
    Dim doc As Object
    Dim Topic As Object

    ' Get the current application and active document
    Set app = Application
    Set doc = ActiveDocument

    ' Ensure there is an active document
    If doc Is Nothing Then
        MsgBox "There is no active document."
        Exit Sub
    End If

    ' Get the currently selected topic
    Set Topic = doc.Selection.PrimaryTopic

    ' Ensure a topic is selected
    If Topic Is Nothing Then
        MsgBox "No topic is selected."
        Exit Sub
    End If

    ' Change the text color of the selected topic to red
    ' Assuming full opacity (alpha = 255) and full red color (red = 255), with no green or blue
    Topic.TextColor.SetARGB(255, 255, 0, 0)
End Sub

Replies (2)

photo
2

I am not aware of any way to read the user's current selection in the topic text. This means that neither a macro nor an Add-in could set the text colour in a user-defined selection.

photo
1

i found this:

https://www.mindmanager.com/en/pages/developers/api/20/#MindManager~Notes~SelectedText.html


this can deal /w a topic note's selected text,

so i think may modify for topic text's color? or "hidden" somewhere?


will try later, thx.


This example assigns some Topic Notes, selects some text and modifies it
Macro (VBScript)
' Replace selected text in Topic Notes
Option Explicit
Sub Main
    With AllDocuments.Add
        With .CentralTopic.AddSubTopic("Topic with Notes").Notes
            .Text = "hello world"
            .SetSelection(1, 6) ' select "hello"
            .SelectedText = "greetings" ' change selected text
        End With
    End With
End Sub

Leave a Comment
 
Attach a file