Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA for Word Table

Status
Not open for further replies.

ITChick526

Technical User
Sep 26, 2008
15
I have a word document with 9 tables
1 row each with checkboxes

When a checkbox value is false, I have written some to code to delete the corresponding row. The problem is once a row is deleted, it throws of the table number of the remaining tables. I can't find a way to work around this?? Any suggestions. I am a novice at vba.
 





Hi,

The Delete Method is fraught with pitfalls.

Generally, it is best to loop from the END to the BEGINNING. Then deleting any object does not disturb the remaining objects in the collection from that point upward.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for the response..but I am really a novice, so can you give me a more specifice example of how to loop at the end if you can.. Thanks. I am using a conditional if statement..i.e

If checkbox1.value = True Then

action

else

delete table row

end If
 



Post your code that is not working.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If CheckBox1.Value = True Then

CheckBox1.Width = 100

Else
Tables(1).Rows(1).Delete

End If

If CheckBox2.Value = True Then

CheckBox2.Width = 100

Else

Tables(2).Rows(1).Delete

End If

This code causes table 2 to become table 1 once the first table is deleted..I know my code sucks but I am really new to this and my document will eventually have about 30 tables one row each with a checkbox.
 



Assign Names to your table objects or use the default table names

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 





On further thought, table names will not help you.

Please explain your process and purpose for selecting this table.

What are you trying to accomplish?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I am trying to create a word document, that if a user does not check a certain checkbox, the text in the table next to it will disappear, to remove data that does not need to appear on the document.

I have to do it in tables because some of the questions have drop down boxes..the table helps keep everything formatted.
 




So what wrong with tables(1) disappearing?

You will have Tables.Count tables remaining.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
The problem is the form will have about 30 questions and I will never know which checkboxes will be checked or not
so that means any random number of tables need to be deleted at once, depending on which check boxes are checked

so for example...If checkbox 1 is not selected it becomes deleted and then table 2 now becomes table 1, that in turn will cause the wrong tables to be deleted after that point
 





Is there a reason for designing this in Word?

Excel has rows that you can HIDE rather than delete. As I first stated, the Delete Method is fraught with peril.

I would seriously rethink your design.

Why must tables be DELETED? Surely there are other methods for accomplishing some greater purpose.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

The reason I chose word is because these are court forms and that have to be filled out as forms. The questions that remain on form will then need to be transferred to another word document..etc

Believe me I already thought of excel but it will not work the way the users need to use this form.

I am really just looking for simple way that when users do not check a certain checkbox, the corresponding text will disappear. I know it can be done..i just need some vba tips
 
Or if there is anyway that once I have cleared the contents of the rows that do not apply for vba to just delete the tables that are blank is another way to go..

Help I am clueless
 





So the user CHECKS the portions that they want to appear.

Then the VBA procedure transfers the paragraphs that are CHECKED to "another word document..etc"

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Exactly..the user will check the orders that apply to the case, and then the selections will be transferred to another word document for other usage

I thought if I could get the questions that do not apply to be removed it will be easy to get the remaining question that are left to another documents by usings bookmarks etc..
 



...but then you discovered that DELETING tables wreaks havoc.

Reminds me of the guy who went to the doctor and told him, "Doc, my head hurts when I hit it with a hammer."

The doctor replied, "Stop hitting your head with a hammer!"

Of course, he charged him a fee for the office visit. ;-)

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
So what are you saying Skip?? I will stop deleting the tables if there is a better way to go, do you have any suggestions???
 





I already offered you a suggestion several posts previous (26 Sep 08 16:00).

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I am sorry but I did not see a working suggestion besides the questions about what I was trying to accomplish and you mentioned not to delete tables..but there was no alternatives offered besided Excel which will not work in my case..Thanks for your time
 



SkipVought said:
So the user CHECKS the portions that they want to appear.

Then the VBA procedure transfers the paragraphs that are CHECKED to "another word document..etc"

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top