AnsweredAssumed Answered

Add text to a General Table via Macro/VBA

Question asked by Steve Cotterill on May 30, 2018
Latest reply on May 31, 2018 by Steve Cotterill

Noob here,


I have only been using SW2018 for a couple of months and I have only started creating VBA code in the past week.


I have been working on a project which has taken a design task from ~1 hour to complete long-hand to ~20 seconds with VBA .  To finish of the project I would like to take some data from Excel and paste it into a drawing as a general table (not as an embedded OLE object).


I can create a table of the correct size (columns and rows) and I can rename it to what I want (in this case "Tube Bend Table").


What I can't do is add the text I require into the cells that I want via VBA.


I have worked out the following: -


1. Even though I have renamed the table "Tube Bend Table" and is listed in the feature manages as such it is actually "DetailItem58@Sheet1".

2. I can add the text I require into the cells as long as I call up "DetailItem58@Sheet1"

example code (obtained from recording a macro in SW): -

boolstatus = Part.Extension.SelectByID2("DetailItem58@Sheet1", "ANNOTATIONTABLES", 0, 0, 0, False, 0, Nothing, 0)

Set myTable = Part.SelectionManager.GetSelectedObject5(1)

myTable.Text(0, 0) = "Text in cell 0,0"

myTable.Text(1, 2) = "Text in cell 1,2"


3. Changing the the first line of the code to: boolstatus = Part.Extension.SelectByID2("Tube Bend Table", "ANNOTATIONTABLES", 0, 0, 0, False, 0, Nothing, 0) does not work.


Can a clever guru point me in the correct direction (i.e. write the code) for me to be able to create a table, rename it, add text to cells?  I know I've done some of this already, but it would be nice to know how a programmer would do it rather than a googled code copier like me.