Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-14-2017, 11:28 AM
kevinbradley57 kevinbradley57 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2017
Posts: 25
kevinbradley57 is on a distinguished road
Default 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
Attached Files
File Type: dotm Audit Report Ver 1.1e.dotm (133.8 KB, 2 views)
Reply With Quote
  #2  
Old 09-14-2017, 02:35 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Quote:
Originally Posted by kevinbradley57 View Post
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.
In that case, you need to revisit how you're managing the process. The placeholder text should remain for testing, regardless of whether it's visible. What are you testing: the placeholder text or the displayed text?
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 09-14-2017, 02:57 PM
kevinbradley57 kevinbradley57 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2017
Posts: 25
kevinbradley57 is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 09-14-2017, 04:03 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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:
http://www.msofficeforums.com/word-v...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
[MS MVP - Word]
Reply With Quote
  #5  
Old 09-14-2017, 05:57 PM
kevinbradley57 kevinbradley57 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2017
Posts: 25
kevinbradley57 is on a distinguished road
Default

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?
Reply With Quote
  #6  
Old 09-14-2017, 07:01 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Quote:
Originally Posted by kevinbradley57 View Post
can you also suggest a single, comprehensive resource for learning VBA coding from the ground up?
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
[MS MVP - Word]
Reply With Quote
  #7  
Old 09-15-2017, 06:25 AM
kevinbradley57 kevinbradley57 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2017
Posts: 25
kevinbradley57 is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 09-15-2017, 03:27 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #9  
Old 09-21-2017, 11:36 AM
kevinbradley57 kevinbradley57 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2017
Posts: 25
kevinbradley57 is on a distinguished road
Default

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.
Reply With Quote
  #10  
Old 09-21-2017, 04:58 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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:
http://www.msofficeforums.com/word-v...tml#post119230
http://www.msofficeforums.com/word-v...ire-table.html

For adding entire tables with content controls, take a look at:
http://www.msofficeforums.com/word-v...tml#post118315

None of these messes with the content control locked state.

For content control deletions, take a look at:
http://www.msofficeforums.com/word-v...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
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


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


All times are GMT -7. The time now is 02:08 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft