|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Code to find a named (bookmarked?) table, replicate a row or table, and delete a specified table.
The attached template uses a QAT icon to replicate either a single table row or an entire table, including the content controls but without any entered text. It works as designed, but it identifies the table by placeholder text that won't necessarily be there if the user completes the table before adding another one, which is likely to happen. So, I need another way to identify the table. I'm familiar with bookmarks, but not how to write the code that would locate the table and replicate it. I also need a QAT icon that would delete the table the cursor happens to be in at the moment along with the subsequent paragraph marks.
I would greatly appreciate any assistance, especially if any suggested code includes enough comments for a VBA rookie to figure out what the code is doing. Kevin Bradley |
#2
|
||||
|
||||
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Paul,
Thanks for the prompt response. I'm not sure what you mean by testing. Currently, the "Insert Row/Table" QAT icon only replicates a table if the placeholder text "[Issue Title" is in the first cell. The user will quite likely replace the placeholder text with "real" text and then try to replicate the table, but the code will then only replicate the last row of the table rather than the entire table. I agree that the process should be revisited. The above is just one of the reasons I would like to change from having a single icon for replicating both a row and table to having two separate icons. Since the original code was written, we've added another table that we want to be able to replicate, but it won't have the same placeholder text that tells the existing code whether to replicate a row or an entire table. |
#4
|
||||
|
||||
Your reference to 'placeholder text' has been quite misleading; it seems all you're referring to is some boilerplate text in the first cell of a table; in the context of a document using many content controls, where 'placeholder text' has a particular meaning, your use of the same term for something totally unrelated causes confusion. of course, the simple solution in this case would be to actually add a content control with some appropriate 'placeholder text' and/or a suitable title so you can test that instead of the raw cell content.
Frankly, though, you code needs a lot more attention than just that; your unlocking/locking of content controls, for example, is quite unnecessary. For adding table rows with content controls, for example, have a look at: https://www.msofficeforums.com/word-...tml#post119230. And, for adding entire tables with content controls, have a look at: http://www.vbaexpress.com/forum/show...l=1#post369226
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Paul -- I wasn't aware that "placeholder text" has a particular meaning when dealing with content controls. Thank you for pointing that out. Thank you, also, for your overall guidance and candor. The code that needs more attention was actually the result of me paying someone to do it rather than me try to figure it out. I will study the examples you provided, but can you also suggest a single, comprehensive resource for learning VBA coding from the ground up?
|
#6
|
||||
|
||||
There is no such resource that I am aware of. There are many books on VBA programming, mostly for Access & Excel, but few would go into any depth with content controls. IMHO, your best resources are to be found in forums like this one.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
That's what I have found also, hence my decision to pay someone. Oh well.
I like the efficient elegance of your code. Are there others whose code you consider to be worth studying? Last edited by kevinbradley57; 09-15-2017 at 12:14 PM. Reason: Fixed typos |
#8
|
||||
|
||||
In the forum space, I'd consider Graham Mayor and Greg Maxey, both of whom contribute to this board and both of whom have their own websites as quite good coders. Others include Doug Robbins (active on various boards) & Hans Vogelaar (who runs Eileen's Lounge). I'm sure there are many others, too. Naturally our coding styles differ somewhat.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Thanks. Greg was actually the person who wrote the code in question. Perhaps I wasn't clear with him about what I needed it to do, but I'm wondering why he included the unlocking/locking of the content controls if it's unnecessary. Perhaps that's just one of those style differences.
|
#10
|
||||
|
||||
Unlocking content controls (if locked) is only necessary when deleting them, not when adding rows. Unlocking & relocking may just be a coding-style thing, but it's quite unnecessary when adding rows.
For adding rows with content controls to a table, take a look at: https://www.msofficeforums.com/word-...tml#post119230 https://www.msofficeforums.com/word-...ire-table.html For adding entire tables with content controls, take a look at: https://www.msofficeforums.com/word-...tml#post118315 None of these messes with the content control locked state. For content control deletions, take a look at: https://www.msofficeforums.com/word-...tml#post118924 Even then, unlocking them is unnecessary if they're not already locked, as the subsequent posts seem to suggest was the case (the .LockContentControl = False line was omitted by the OP).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word Macro to delete table row and table header | NorthSuffolk | Word VBA | 6 | 10-11-2016 05:04 AM |
Want to delete balnk line row from table with MS word using VBA code | jarunsona | Word VBA | 3 | 07-21-2016 04:54 AM |
Creating VBA Code to Delete Empty Column in Table | Faugs | Word VBA | 5 | 08-07-2014 03:29 PM |
Referencing rows of a table at a bookmarked location based on the value of a column | jpb103 | Word VBA | 11 | 05-22-2014 08:33 AM |
VBA Code to take data from a table in word document and place it in a summary table | VBLearner | Word VBA | 1 | 03-09-2014 08:42 PM |