Table from Excel spreadsheet that has Macros

Table from Excel spreadsheet that has Macros

Anonymous
Not applicable
3,594 Views
6 Replies
Message 1 of 7

Table from Excel spreadsheet that has Macros

Anonymous
Not applicable

I am having trouble creating a TABLE in Acad 14 from a Data Link created from an Excel file that has VBA macros.  I can make the link and it shows up in the Data Link Manager but when I make a TABLE the link is not on the list.  If I try to make a table directly by making a "Paste Special" the command just ends without coming up with the table.

I can make another spreadsheet that gets it's data from the macro one & then link to this "non-macro" spreadsheet & it works fine.

I have tried every kind of Excel file: xls, xlsx, xlsm.  Same situation. 

I have tried making a sheet in the excel file that but with no macros linked to it,  doesn't work, same result.

0 Likes
3,595 Views
6 Replies
Replies (6)
Message 2 of 7

pendean
Community Legend
Community Legend
Excel based VBA macros don't work in AutoCAD: but just to be sure what you asked is correct, any chance you can post an Excel file here with your macros intact for someone to try?
0 Likes
Message 3 of 7

Anonymous
Not applicable

Dean,

Thanks for considering my problem.

To clarify,  I am not trying to get the excel macros to work from within Autocad.  I am just making a table with the data from the cells of the excel worksheet.  Even if I make a new sheet withn the workbook that has no macros associated with it I still cannot get the cell data into Autocad.  It seem like Acad does not like the spreadsheet if it has any macros in it. 

I tried deleting the Macros & when they are all removed then the TABLE works in Acad.  I could not get any consistant results by deleting the macros progressively 1 at a time. 

I tried to send teh excel file but it is 6 MB & Autodesk only allows files up to 5 MB in size.

0 Likes
Message 4 of 7

Anonymous
Not applicable

If you are trying to create a table In AutoCAD from an actual "Table" or "Chart" object in Excel, that probably won't work, or at least I don't know how to work it. If by "Macros" you mean custom user forms, dialog boxes, or other VBA objects, that probably won't work either. Just data of whatever type stored in worksheet cells, whether it is created by Macros (sub or function), by in-cell formulas or functions, or by typing text in the cells shouldn't make any difference. I  use tables in AutoCAD linked to Excel sheets, both with and without Macros in the Excel files, quite often, and the Macros in the files make any difference at all. (.xls, .xlsx, or .xlsm, all work equally well) This has worked for me since Acad 2013, up thru Acad 2016. The "trick" is to create a named range in the Excel file that spans all of the cells that you want to link. If you want to link more than 1 range of cells, you will need to create a named range for each range of cells you want to link, and a separate AutoCad table for each one. In the AutoCad data link dialog box, after browsing to and selecting the Excel file you want to link to, select the worksheet that contains your target data, then select the option "Link to a named range"- select your desired named range from the dropdown, other options as desired, then hit "OK" In AutoCad, start the "Insert Table" command (from Ribbon, keyboard entry, or however you have it set up for easiest access), select your desired table style from the dropdown (I recommend setting one up with whatever your desired text styles, cell styles, etc. are- once you have a table created, AutoCad sometimes gets "fussy" about letting you change things after the fact) then select the "From a data link" option, and hit "OK". Place your table in the desired location in your drawing, and that's it. To update the table whenever you make (saved) changes in the Excel file, you can select the data link from the X-ref pallete, right-click and select "Update data links", or by selecting the Acad table and right-clicking it, then hit "Download changes from Source File" (there are probably other ways too, but these are the 2 I use) If your macros in excel do anything as far as adding cells, rows or cloumns, make sure that they do so in a fashion that keeps the new data inside of your named range.

 

Hopefully the screenshots will help illustrate...good luck. If this doesn't help, if you can post the .dwg and excel file you are trying to link, along with an explanation of what data you are trying to capture, I will see what I can do.

 

P.S.- I haven't tried using VBA from Excel to run AutoCAD for a long time (Excel 2003/AutoCAD 2006), but back then it worked quite well, I had an Excel sheet that you could go thru a sequence of drop down selections to configure products-custom wood doors and accessories, if it matters- and when you had all of the options selected, Excel would then send commands to AutoCAD and AutoCad would draw the product you had configured. I assume that as long as you load the correct activeX and type libraries in Excel VBA, and you have the VBA enabler installed for AutoCAD, again having the correct activeX and type libraries loaded, there is no reason why either one shouldn't be able to call and send commands to the other one now. VBA syntax in Excel hasn't changed, so I assume it is still the same in AutoCad...(?)

Message 5 of 7

Anonymous
Not applicable

Daniel,

Just making a simple table from teh datain excel file.  Have now found that it works on some machines in our office and not on others.  Seems to work best with Autocac MEP. 

I have no problem making the  tables from an excel file that does not have the macros.

k warddrip

0 Likes
Message 6 of 7

ToanDN
Consultant
Consultant

Create a new Excel file and use Data Connections to link its worksheet to the existing Excel file.  Use this new Excel file to Datalink to AutoCAD table.

0 Likes
Message 7 of 7

Anonymous
Not applicable

Ended up doing exactly what you suggest for lack of any other more elegant solution.

Will have IT explain why it works on some machines and not on others.

0 Likes