IMPORT EXCEL TABLE FROM SAME FOLDER AS IDW

tancredi.barbuscia
Contributor
Contributor

IMPORT EXCEL TABLE FROM SAME FOLDER AS IDW

tancredi.barbuscia
Contributor
Contributor

Hallo, i wrote this ilogic code that helps me to import an excel table in my .idw file.

i need to write a code that can import the excel table from the folder of the .idw file.

in this way i can use aexcel tables in any folder, and not just one

 

Sub Main ()  CreateDrawingExcelTable()    
    ' Set a reference to the active drawing document
    Dim oDrawDoc As DrawingDocument
     oDrawDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet
    Dim oActiveSheet As Sheet
     oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Create the placement point for the table
    Dim oPoint As Point2d
     oPoint = ThisApplication.TransientGeometry.CreatePoint2d(25, 25)
    
    ' Create the table by specifying the source Excel file
    ' This assumes that the first row in the Excel sheet specifies the column headers
    ' You can specify a different row using the last argument of the AddExcelTable method
    Dim oExcelTable As CustomTable
     oExcelTable = oActiveSheet.CustomTables.AddExcelTable("C:\Users\barbusciat\Desktop\test.xlsx", oPoint, "Tabella colori")
End Sub 

 

0 Likes
Reply
Accepted solutions (1)
527 Views
5 Replies
Replies (5)

FINET_Laurent
Advisor
Advisor

You can get the active document path like this :

MsgBox(ThisApplication.ActiveDocument.FullFileName)

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes

mcgyvr
Consultant
Consultant

This just gets the path so you don't need to strip out the idw filename/extension..

MsgBox(ThisDoc.Path)


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes

mcgyvr
Consultant
Consultant
Accepted solution

So you could change your code as follows or something..

Dim oExcelTable As CustomTable

'get the current document path
oCurrentPath = ThisDoc.Path
'define the excel file name
oExcelFileName = "test.xlsx"
'combine the path and the filename
oSaveLocation = oCurrentPath & "\" & oExcelFileName

     oExcelTable = oActiveSheet.CustomTables.AddExcelTable(oSaveLocation, oPoint, "Tabella colori")


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes

Anonymous
Not applicable

@tancredi.barbuscia  What would be the excel filename convention? Same as drawing name?  I suggest to include that on the code for better automation. You can run the rule as external without editing. 

0 Likes

tancredi.barbuscia
Contributor
Contributor

Thanks a lot mate. that was exactly what i was looking for