VBA - Undefined user defined type - type defini par l'utilisateur non défini

VBA - Undefined user defined type - type defini par l'utilisateur non défini

emile.bergin3WG83
Explorer Explorer
1,227 Views
2 Replies
Message 1 of 3

VBA - Undefined user defined type - type defini par l'utilisateur non défini

emile.bergin3WG83
Explorer
Explorer

Dear all,

with VBA in autocad 2021,  I want to read inside an excel file. 

The code is pretty simple : 

  Private Sub CommandButton2_Click()
    Dim ExcelAppObj As Excel.Application

    Set ExcelAppObj = New Excel.Application ' Lance Excel
    ExcelAppObj.Visible = True ' Affiche Excel
    ExcelAppObj.InputBox ("Coucou de la part d'AutoCAD !") ' Affiche un message depuis Excel
    ExcelAppObj.Application.Quit ' Quitte Excel
End Sub

 

First line "Dim ExcelAppObj As Excel.Application" creates an "Undefined user defined type" error and I cannot understand why. Can someone help ?

 

Autocad is installed in C:/program files/, so should be 64bits

I use Excel from Office 365

 

0 Likes
Accepted solutions (2)
1,228 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Assume you have Excel installed in the computer (any computer where your AutoCAD VBA code is to run).

 

You need to add reference to MS Excel object library (VBA editor->menu "Tools..."->References...-> select/check the item "Microsoft Excel 16.x Object Library").

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

emile.bergin3WG83
Explorer
Explorer
Accepted solution

Thanks Norman!

It was already selected ... but did not work.

So I unselect all and reselect ... and it works !!

0 Likes