Home > Software engineering >  Real-time error "91" object variables or with block variable is not set
Real-time error "91" object variables or with block variable is not set

Time:09-20

Private Sub cmdDraw_Click ()
Form1. Hide


Dim swapp As Object
Dim part As Object
The Set swapp=CreateObject (" Sldworks. Application ") 'create or obtain Sldworks object
The Set part=swapp. NewDocument (CurrentDir + "\ temp \ bearing. Prtdot", 0, 0, 0) 'open model

Dim fileName As String
FileName=part. Gettitle 'get the fileName


Dim CurCFG As Object
The Set CurCFG=part. GetActiveConfiguration () 'configuration

Dim ConfName As String
ConfName=CurCFG. The Name 'configuration Name,



Boolstatus=part. The Extension. SelectByID (1 D6 @ sketch "@" + fileName + "SLDPRT", "DIMENSION", 0.1448, 0.0612, 0.0165, False, 0, Nothing)
Part. The Parameter (" 1 D6 @ sketch "). The SystemValue=HTTP://https://bbs.csdn.net/topics/txtWj.Caption/1000 'change of outside diameter
Boolstatus=part. The Extension. SelectByID (" D1 @ sketch 1 @ + fileName "+" SLDPRT ", the "DIMENSION", 0.041, 0.0415, 0.00516, False, 0, Nothing)
Part. The Parameter (" 1 "D1 @ sketch). SystemValue=HTTP://https://bbs.csdn.net/topics/txtNj.Caption/1000 'change the target inside diameter
Boolstatus=part. The Extension. SelectByID (" D4 @ @ sketch 1 + fileName "+" SLDPRT ", "DIMENSION", 0.00518, 0.05451, 0.008906, False, 0, Nothing)
Part. The Parameter (" D4 @ sketch 1 "). The SystemValue=HTTP://https://bbs.csdn.net/topics/txtHd.Caption/1000 'change the target thickness
Part. EditRebuild
Part. ShowNamedView2 test "such as" * axis, 7
Part. ViewZoomtofit2
Add attributes'
Part. AddCustomInfo3 ConfName, "code", swCustomInfoText, txtBs. Caption
Part. AddCustomInfo3 ConfName, "name", swCustomInfoText, "single-row radial ball bearings"
Form1. Show
End Sub

CodePudding user response:

I don't know where the LZ do code?

CodePudding user response:

reference 1st floor zdingyun response:
I do not know now where to get the code?


Sldworks machinery industry is a more famous CAM software,


The correlation with "industry" is bigger,
Check out...

CodePudding user response:

If it is " fileName=part. Gettitle "that suggest a 91 error,
Obviously, in front of the sentence: the Set part=swapp. NewDocument (CurrentDir + "\ temp \ bearing. Prtdot", 0, 0, 0) 'open model
No successful execution, should check the building Lord:
1. The file path is correct?
CurrentDir is likely to be on "work environment" and instruction execution of code, you should be in the other place to set breakpoints,
When performing the to this sentence, confirm whether "CurrentDir" path for you need!

2. Are you sure the "open" existing project file, not with "Openxxxxx" function, but this "Newxxxxx" function?

3. Check the related documents, confirm your "NewDocument ()" biography of several other parameters are correct (assuming it does is to use this function),

CodePudding user response:

The Set swapp=CreateObject (" Sldworks. Application ")
It is best to check, after performing swapp is object created again, add a monitor what of, look at the sentences before and after the execution did swapp,
If this is no problem that problem is bound to the next sentence,
The Set part=swapp. NewDocument (CurrentDir + "\ temp \ bearing. Prtdot", 0, 0, 0)
Upstairs on the analysis of the already very detailed

CodePudding user response:

VBA rooted in various industry software, do not know what to use vb language out whether these are counted in,

You step through the building Lord part right click on the add monitoring,

The Set part=swapp. NewDocument (CurrentDir + "\ temp \ bearing. Prtdot", 0, 0, 0)
Here again to switch to the full path test see if the file path problem, and then the back three parameters under the careful research, it is open to the front-end display, remember to use com to open the PPT file will have to set the parameters of operation, or are unable to action object,

CodePudding user response:

The Set swapp=CreateObject (" Sldworks. Application ")
Must perform a success, otherwise it's the next line can not be performed, when performing the sentence would be an error;
Rather than in the back of the fileName=part. Gettitle just an error,

CodePudding user response:

All commented On the Error Resume Next statement, run in the IDE,
The error and then click the debugging, the cursor will stop error in the statement,
Or
In doubt may have a logical error statements in advance to set breakpoints, run through the breakpoint interrupt,

At this point can be used in the immediate window
? The variable name
Or
? The function name () function parameter
Or
Process (parameters)
Auxiliary debugging,
  •  Tags:  
  • VBA
  • Related