VBA macro to get formatting text form the selected SOLIDWORKS note

Edit ArticleEdit Article

Formatted note text
Formatted note text

This VBA macro copies the value of formatted text from the selected note in SOLIDWORKS part, assembly or drawing and copies the value to the clipboard.

Formatted note text includes font information (size, style, color), align, paragraph properties, etc.

Note formatting
Note formatting

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks
    
    Dim swModel As SldWorks.ModelDoc2
    
    Set swModel = swApp.ActiveDoc
    
    If Not swModel Is Nothing Then
    
        Dim swSelMgr As SldWorks.SelectionMgr
        
        Set swSelMgr = swModel.SelectionManager
        
        Dim swNote As SldWorks.Note
        
        Set swNote = swSelMgr.GetSelectedObject6(1, -1)
        
        If Not swNote Is Nothing Then
            Dim prpLinkedText As String
            prpLinkedText = swNote.PropertyLinkedText
            SetClipboard prpLinkedText
            Debug.Print prpLinkedText
        Else
            Err.Raise vbError, "", "Select note"
        End If
        
    Else
        Err.Raise vbError, "", "Open the model"
    End If
    
End Sub

Sub SetClipboard(text As String)
    
    Dim vText As Variant
    vText = text
    
    Dim htmlFile As Object
    Set htmlFile = CreateObject("htmlfile")
    
    htmlFile.parentWindow.clipboardData.SetData "text", vText

End Sub

Product of Xarial Product of Xarial