Macro, search for value note and change

Hello

In a drawing, I'm looking to change two notes related to solidworks properties

In my example, the note is linked to these two properties:  $PRPSHEET:"DESIGNATION_FR"$PRPSHEET:"DESIGNATION_FR2"

I want to replace it with $PRPSHEET:"DESIGNATION_FR"$PRPSHEET:"DESIGNATION_FR2"($PRPSHEET:"NUMERO_PLAN")

and I have another one to change $PRPSHEET:"DESIGNATION_UK"$PRPSHEET:"DESIGNATION_UK2"

$PRPSHEET:"DESIGNATION_UK"$PRPSHEET:"DESIGNATION_UK2"($PRPSHEET:"NUMERO_PLAN")

I don't want to apply these changes on all sheets (on average about ten)  except for the 1st

I started this macro with find and search but it doesn't work the way I want it to.

 

Do you have an idea?

Thank you in advance for your feedback

here is attached my macro

Cdlt

Hello

Can you attach the code you currently have

Hello Jerome,

However, I had attached the files in the description.

Here's the macro


macro1.swp

and my working file


test.zip

A start of a runway:

https://www.lynkoa.com/forum/mises-en-plan/modifier-une-note-sur-un-fond-de-plan-solidworks-avec-une-macro?page=1

1 Like

Try this. It will change the notes on each sheet except the first one.

Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swNote As SldWorks.Note
Dim vSheets As Variant
Dim i As Integer
Dim vNotes As Variant
Dim vNote As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
vSheets = swDraw.GetSheetNames
For i = 1 To UBound(vSheets)
    swDraw.ActivateSheet vSheets(i)
    Set swView = swDraw.GetFirstView
    vNotes = swView.GetNotes
    For Each vNote In vNotes
        Set swNote = vNote
        If InStr(swNote.PropertyLinkedText, "$PRPSHEET:""DESIGNATION_FR") > 0 Then
            swNote.PropertyLinkedText = "$PRPSHEET:""DESIGNATION_FR""$PRPSHEET:""DESIGNATION_FR2""($PRPSHEET:""NUMERO_PLAN"")"
        ElseIf InStr(swNote.PropertyLinkedText, "$PRPSHEET:""DESIGNATION_UK") > 0 Then
            swNote.PropertyLinkedText = "$PRPSHEET:""DESIGNATION_UK""$PRPSHEET:""DESIGNATION_UK2""($PRPSHEET:""NUMERO_PLAN"")"
        End If
    Next
Next
End Sub

 

3 Likes

Thank you Jerome

1 Like