Edit General Table Cells With VBA/iLogic

Edit General Table Cells With VBA/iLogic

mfoster9TD82
Advocate Advocate
582 Views
6 Replies
Message 1 of 7

Edit General Table Cells With VBA/iLogic

mfoster9TD82
Advocate
Advocate

Hello, 

I'm trying to edit the cells of general table but I can't seem to get it right. I'm pretty new with VBA, could someone give me a sample code for doing this, I can't seem to find anything for a general table. VBA or iLogic is fine.

 

This is what I have now but I keep getting the error :

"Object reference not set to an instance of an object."

 

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document

Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet

Dim oRow() As String
oRow(1) = "A"
oRow(2) = "INITIAL RELEASE"
oRow(3) = Date.Now
oRow(4) = "MF"



'Asuming a revision table is on the sheet
Dim oRevTable As CustomTable
oRevTable = oSheet.CustomTables.Item(1)

'Change the value of the first cell of row 1
oRevTable.Rows(1).Item(1).Text = oRow(1)
'Change the value of the second cell of row 1
oRevTable.Rows(1).Item(2).Text = oRow(2)
'Change the value of the third cell of row 1
oRevTable.Rows(1).Item(3).Text = oRow(3) 
'Change the value of the fourth cell of row 1
oRevTable.Rows(1).Item(4).Text = oRow(4) 

 

Thanks!

0 Likes
Accepted solutions (1)
583 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

I see a couple of things that may be causing problems.  First of all, when creating an array, you need to keep in mind that they are zero based, which means their first Item is Item(0), not Item(1).  Next, with arrays, 'size matters', so you must either specify how many values/positions it will contain within the (), then you can fill in the values for those slots in later rows; or you must not specify how many values/positions, then directly supply the set of values after the = sign within {}.  One or the other.  You are not specifying the array's size, and are not directly supplying its set of values after the = sign, so that may cause a problem.

 

Next, a RevisionTable is not necessarily a CustomTable.  If you have a RevisionTable on your sheet, but don't have a CustomTable on your sheet, then oSheet.CustomTables.Item(1) will cause the error you saw, because it is trying to refer to something that is not there.

 

PS:  Here is a link to another post where I have a code for modifying/setting contents of a CustomTable in a drawing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

Michael.Navara
Advisor
Advisor
Accepted solution

There are few mistakes

  1. Arrays must be initialized with values or with fixed size
  2. Arrays are indexed from 0 (zero) by default

 

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document

Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet

'Array must be initialized with values
'Dim oRow() As String = {"A", "INITIAL RELEASE", Date.Now, "MF" }

'Or with fixed size
'Arrays are indexed from 0 by default
Dim oRow(4) As String
oRow(0) = "A"
oRow(1) = "INITIAL RELEASE"
oRow(2) = Date.Now
oRow(3) = "MF"

'Asuming a revision table is on the sheet
Dim oRevTable As CustomTable
oRevTable = oSheet.CustomTables.Item(1)

'Change the value of the first cell of row 1
oRevTable.Rows(1).Item(1).Value = oRow(0)
'Change the value of the second cell of row 1
oRevTable.Rows(1).Item(2).Value = oRow(1)
'Change the value of the third cell of row 1
oRevTable.Rows(1).Item(3).Value = oRow(2)
'Change the value of the fourth cell of row 1
oRevTable.Rows(1).Item(4).Value = oRow(3) 

 

 

0 Likes
Message 4 of 7

mfoster9TD82
Advocate
Advocate
Thanks for the array tip. Also I don't think it is a revision table by form, its a general table used as a revision table(I didn't make the template, that's just how they do it here...)
0 Likes
Message 5 of 7

mfoster9TD82
Advocate
Advocate

Thanks, I think this helped most of the way. Now it's giving me the error: "Public member 'Text' on type 'Cell' not found."

 

I'm not sure what this means, I made sure I had the correct table in my sheet and I can edit the table manually

0 Likes
Message 6 of 7

Michael.Navara
Advisor
Advisor

Sorry. I fixed this issue but I don't described it. Table cell has not property Text but Value. See my code. 

0 Likes
Message 7 of 7

mfoster9TD82
Advocate
Advocate
Oops, I missed that. Thanks it worked!
0 Likes