Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

API, changing active sheet on multiple sheet drawing

Status
Not open for further replies.

WilliUSF

Mechanical
Feb 6, 2002
8
Hey all,

I am trying to change the focus from one sheet to another in a SolidWorks drawing using VBA.

Below is a clip from my macro. The swDraw.GetCurrentSheet line works fine so I think I have the correct libraries loaded but the swDraw.SheetNext (or SheetPrevious) does not work. I get "Compile Error: Expected Function or Variable"
and the .SheetNext is highlighted. I checked spelling and all. I dim'd the swNextSheet as Sldworks.Sheet as I did swsheet.

Set swsheet = swDraw.GetCurrentSheet
Set swNextSheet = swDraw.SheetNext

I'm still pretty new at VBA especially in SolidWorks.

Any help's appreciated

Thanks
 
Replies continue below

Recommended for you

According to API help, swDraw.SheetNext returns nothing. You should not be trying to use it with the Set statement
 
You can use the ActivateSheet method, but you need the sheet name. With an array of sheet names, you can activate the first sheet that is not the active sheet. Here's a little sample.
Code:
    Dim swApp As SldWorks.SldWorks
    Dim swModel As ModelDoc2
    Dim swDwg As DrawingDoc
    Dim swSht As Sheet
    Dim sThisSheet As String
    Dim sSheetNames As Variant
    Dim iSheets As Integer
    Dim j As Integer
    
    
    Set swApp = GetObject(, "SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swDwg = swModel
    
    Set swSht = swDwg.GetCurrentSheet
    sThisSheet = swSht.GetName
    
    iSheets = swDwg.GetSheetCount
    sSheetNames = swDwg.GetSheetNames
    For j = LBound(sSheetNames) To UBound(sSheetNames)
        If sSheetNames(j) <> sThisSheet Then
            swDwg.ActivateSheet sSheetNames(j)
            Exit For
        End If
    Next j

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor