Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JelteDeJong
in reply to: Patrick1323

i could not find a command for Replacing a text style. But i found a way to delete the style and copy the other. it works like this:

Dim originalStyleName As String = "ReplaceMe"
Dim replaceBy As String = "replaceWithMe"

Dim doc As PartDocument = ThisDoc.Document
Dim def As PartComponentDefinition = doc.ComponentDefinition

Dim textStyleOrg As TextStyle = Nothing
Dim textStyleNew As TextStyle = Nothing
For Each style As TextStyle In doc.TextStyles
    If (Style.Name = originalStyleName) Then
        textStyleOrg = Style
    End If
    If (Style.Name = replaceBy) Then
        textStyleNew = Style
    End If
Next

textStyleOrg.Delete()
textStyleNew.Copy(originalStyleName)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com