[VBA, paste text to all subtopics'notes01] I am writing a macro for this fx, suggestions wellcomed.

charles c. shared this question 20 days ago
Discussion Open

hi,

i knew some programming from high school/college,

let's see if i could make a macro as the title suggest.

usage:

i got a tree of topics, i wanna select the top one and then paste text to all subtopics' notes. (add to, not append).


From previous reading,

when i select a topic, i could easily get a collection of subtopics by the "allsubtopics" property.


but i duno how to access it, then i found this:

recently found a doc from ms on how to access a list's items.

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/collection-object


from previous post, i already knew how to write text into a topic's note.


so i think combine both will make it.


let's see

Replies (5)

photo
1

hey, for pasting text to multi SELECTED topics, the VBA is almost here:

'#Language "WWB-COM"

Option Explicit

Sub Main
	Dim docCurrent As Document ' current Document
	Dim tpcSelected As Topic ' selected Topic
	Dim MyClasses As New Topics
	Dim cwtopic

	Dim X As Long

	Set docCurrent = ActiveDocument
	Set tpcSelected = docCurrent.Selection.PrimaryTopic ' our selected topic
	Debug.Print X
	X = docCurrent.Selection.Count
	Debug.Print X
	For Each cwtopic In docCurrent.Selection
		cwtopic.Notes.Insert("5")

	Next


End Sub
currently you select multiple topics, then it insert "5" into the note.

will be easy to switch that "5" into the content from clipboard.


HOWEVER,

i think choosing a topic and automatically populate into all subtopics is better than "multiple selected", although sometimes you may use 1, sometimes you may use the other.


let's see.

photo
1

i just tried, this script works for me, this is what i want.


there are just come combinations:

note is "add to" vs "append"

"all sub topics" vs "multiple selected"


currently, if you use F4 to hide other brances, then you can still use ctrl-A to select all, and paste.

in this way it functions same as "all sub topics"

photo
1

just wanna point out,

what the script do is "insert text at note start", not append, yet.

photo
1

oh, i removed the unused codes,

used the InputBox as suggested by Nick

and for each Insert cycle, the code will add a new line at first.

turns out only 6 lines of code for doing things, the other 3 is for declaration.

Leave a Comment
 
Attach a file