×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

API, changing active sheet on multiple sheet drawing

API, changing active sheet on multiple sheet drawing

API, changing active sheet on multiple sheet drawing

(OP)
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

RE: API, changing active sheet on multiple sheet drawing

According to API help, swDraw.SheetNext returns nothing.  You should not be trying to use it with the Set statement

RE: API, changing active sheet on multiple sheet drawing

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.

    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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources