Hi,
I am writing a macro having to do with the sheet numbers, and I need to retrieve the value of the current sheet number. It is stored in Solidworks as \\\$PRP:"SW-Current Sheet", but I am having trouble calling this value in the macro. This value is used for the text field "Sheet 1 of 20", with 1 being the current sheet value.
My code only delivers an empty string
Sub ShowCurrentSheetNumber()
' Declare variables
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim customPropertyMgr As SldWorks.CustomPropertyManager
Dim currentSheetValue As String
Dim valout As String
Dim bool As Boolean
' Initialize SolidWorks application
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Ensure the document is a drawing
If swModel Is Nothing Or swModel.GetType() <> swDocDRAWING Then
MsgBox "This macro must be run in a drawing document.", vbExclamation
Exit Sub
End If
' Get the drawing document
Set swDrawing = swModel
' Get the custom properties manager for the drawing document
Set customPropertyMgr = swDrawing.Extension.CustomPropertyManager("")
' Retrieve the evaluated value of "SW-Current Sheet"
bool = customPropertyMgr.Get4("SW-Current Sheet", False, currentSheetValue, valout)
' Display the value if found
If bool Then
MsgBox "Current Sheet Number: " & valout, vbInformation
Else
MsgBox "Property 'SW-Current Sheet' not found.", vbExclamation
End If
End Sub
