0

I wrote a piece of code in VBA of CATIA, using Selection object. I needed an access to a Excel file to get some value from it, so I ticked the library "Microsoft Excel Object Library", but whenever I do that, an error appear with the message "Run-time error '91. Object variable or With block variable not set" (see the image). Otherwise there is no problementer image description here. I can't make out why? Any help would be appreciated, please!

  • Did you put Excel higher that Catia in the list of references? – GSerg Dec 20 '22 at 10:31
  • @GSerg The Excel-related reference is under all of CATIA references which is available by default in VBA of CATIA – Hung Pham Vu Dec 20 '22 at 10:37
  • 3
    Declare your variables then. `Dim Selection As `. – GSerg Dec 20 '22 at 10:39
  • Guessing: `Dim Selection As CATIA.Document.Selection` or `Dim Selection As CATIA.Selection` (You are not currently Dimming it at all) – braX Dec 20 '22 at 11:37
  • 3
    Try using variable names which are not the same as excel object names. Set oDoc = CATIA.ActiveDocument Set oSel = oDoc.Selection oSel.SelectElement2(...) Also, your code will throw that error also if there is no open document in CATIA. – C R Johnson Dec 20 '22 at 13:44

0 Answers0