"Object variable or With block variable not set" error declaring a worksurface

"Object variable or With block variable not set" error declaring a worksurface

Anonymous
Not applicable
2,638 Views
1 Reply
Message 1 of 2

"Object variable or With block variable not set" error declaring a worksurface

Anonymous
Not applicable

I get an error

 

Run-time error '91':

Object variable or With block variable not set

 

when running this code

 

Option Explicit
Dim oWorkSurf As WorkSurface
Dim oWorkSurfs As WorkSurfaces
Dim oSurfBody As SurfaceBody
Dim oSurfBodies As SurfaceBodies
Dim oCompDef As ComponentDefinition
Dim oPartCompDef As PartComponentDefinition
Dim oPartDoc As PartDocument
Dim oSplitFeat As SplitFeature


Public Sub SplitAllFaces()

    Set oPartDoc = ThisApplication.ActiveDocument
    Set oPartCompDef = oPartDoc.ComponentDefinition
    Set oSurfBodies = oPartCompDef.SurfaceBodies
    Set oWorkSurfs = oPartCompDef.WorkSurfaces
    
    oWorkSurf = oWorkSurfs.Item("Srf5")
    
    For Each oSurfBody In oSurfBodies
        
        Set oSplitFeat = oPartCompDef.Features.SplitFeatures.SplitBody(oWorkSurf, oSurfBody)
    
    Next oSurfBody

End Sub

 I'm not sure why.  I've tried Item ("Srf5"), Item(1), and Item("Surface2").  All give the same result.

0 Likes
Accepted solutions (1)
2,639 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

Found the answer, oWorkSurface=.... needs to be   Set oWorkSurface=.....

0 Likes