Hey guys, this is my first time using forums and macros. I was looking at how to switch multiple sheet names and adjust the title in the sheet format. I got the macro to work for the sheets but I can't get the macro for the title. I want to switch whatever text is in the title to "ABC 10 x i" where i changes on each drawing sheet. The sheet follows the same concept where it is just the latter part "10 x i" and i got that to work using:
Sub main()
Dim swApp As Object
Dim swSheet As SldWorks.Sheet
Dim swDraw As SldWorks.DrawingDoc
Dim vSheetNames As Variant
Dim i As Long
UserForm1.ListBox1.Clear
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
Set swSheet = swDraw.GetCurrentSheet
vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
swDraw.ActivateSheet (vSheetNames(i))
Set swSheet = swDraw.GetCurrentSheet
swSheet.SetName "10 X " & (0 + i * 5)
Next i
swDraw.ActivateSheet (vSheetNames(0))
MsgBox ("Complete")
End Sub
This is not my code. I just edited it on a forum I found here. Now I want to use that same for loop configuration and change the title block for each drawing sheet except I'm having trouble getting there. I can understand the coding a little bit but I'm new to these SW classes (or commands), so I don't know how to recall specifically, the title block.
I was using this code below except I don't want to change other stuff in the sheet format, just the title. If it's easier, I have the description for the part already entered in the property configuration manager and this is exactly what I want in the title. So it would be a string in front of the part description. Sorry I should have clarified this earlier but each drawing sheet is a different part configuration so I would like "ABC (part description)" on each drawing sheet title. I'm going to be away from the desk so I may not respond till 3/4 hours later but I would greatly appreciate any help.
'--------------------------------------- | ||
' | ||
' Preconditions: SolidWorks document is open and has a note | ||
' | containing the text string "abc". | |
' | ||
' Postconditions: The text string "abc" is replaced with | ||
' | the text string "def". | |
' | ||
'--------------------------------------- | ||
Option Explicit | ||
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 strNoteText | As String | |
Const strReplaceText | As String = "abc" | |
Const strNewText | As String = "def" | |
Sub main() | ||
Set swApp = Application.SldWorks | ||
Set swModel = swApp.ActiveDoc | ||
Set swDraw = swModel | ||
Set swView = swDraw.GetFirstView | ||
Set swNote = swView.GetFirstNote | ||
While Not swNote Is Nothing | ||
strNoteText = swNote.GetText | ||
strNoteText = Replace(strNoteText, strReplaceText, strNewText, 1, -1, vbTextCompare) | ||
swNote.SetText strNoteText | ||
swModel.WindowRedraw | ||
Set swNote = swNote.GetNext | ||
Wend | ||
End Sub |