#1
|
|||
|
|||
Help with Inserting External Information into Document Consecutively
I'm not entirely sure how to describe what I'm trying to do, but I'll give it a go.
I have a userform with checkboxes. If Checkbox 1 is selected, it copies information from external doc using bookmarks to a bookmark in the activedocument. With this though, I realised that I couldn't add 100+ bookmarks to the one line so I have had to create a new paragraph on the empty sheet for each bookmark. It all works very well, however, if for example I don't select Checkboxes 10-20 then there is a big gap in the document where the paragraphs that contain the bookmarks are still there. I was thinking I might need some code to delete the bookmark if not selected? I have searched and tried my hardest to do this but nothing works. An alternative I was thinking might be to use paragraphs instead of bookmarks in the activedocument but then I'm not sure how to code to tell it to go to the next paragraph, as I can't just say checkbox 1=paragraph 35 checkbox2=paragraph 36 because what if I decided not to select checkbox 1? I hope this makes sense I have attached the document to help with understanding what I mean |
#2
|
||||
|
||||
You have a few choices.
1. Have a single bookmark in the target document and keep adding content to the end of that range. 2. Include a paragraph mark in each bookmark of the source document so they bring in their own paragraphs. 3. Run a step that hides the paragraphs with an empty bookmark.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
If the texts are consecutive, then why bother with the bookmarks at all. Just add them one after another as required. See attached. Create a new document from the template. See also the button on the QAT (Quick Access Toolbar)
As I don't have your source document, I could not test the code, but it should be much closer to what you need and works with a test source, provided the bookmarked texts include the final paragraph marks..
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 10-15-2018 at 04:09 AM. |
#4
|
|||
|
|||
Quote:
For example, we create the document using the userforms etc. Then make all our necessary typing entries into the document. Then in a couple of weeks we find out that we need to add in a section, let's say a swimming pool, if we click on the toolbar button to add it in, then we lose all of the typing that we have done initially. Is there a way around this? |
#5
|
||||
|
||||
I simply made some minor changes to your code so that it would eliminate all those bookmarked paragraphs and moved it to the calling macro.
The only bookmarks in the created document are those of the inserted texts. Instead of writing to bookmarks the texts are written consecutively. The template creates new forms, and are filled with the bookmarked sections. When you click the edit button the form is re-opened with the previous selections checked by reference to the bookmark names. The content is then cleared so that any changes made to the userform are reflected in the edited document. You shouldn't lose anything as it is all re-entered according to what is checked when you click the OK button.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#6
|
|||
|
|||
Quote:
Is there a way to overcome this? |
#7
|
||||
|
||||
If you are going to edit the inserted texts after they have been inserted and then use the process (or any process for that matter) to add or remove the inserted texts, you are creating a whole new bag of worms and it becomes a major programming exercise which is way beyond the assistance I am willing to provide via this forum.
Without knowing what is in the texts and what you are likely to want to change it is impossible to advise how to handle it. If the texts contain editable sections using uniquely named content controls, then it should be possible to record not only the bookmarks inserted, but the values of those content controls, and re-apply the stored values to the named controls when the document is rebuilt. Otherwise you are going to have to compare what you had with what you want and work out a way to insert any additional texts in the correct places.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#8
|
||||
|
||||
The method 3 I suggested whereby each bookmark's range can be hidden is the only one that works with your described requirements. Have you tried that yet?
The bookmarks cannot be completely emptied (because the order will become confused) but they could contain only a paragraph mark which can be hidden.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#9
|
||||
|
||||
This problem got the better of my curiosity and on simplifying the code to avoid all those interminable sections relating to check boxes and bookmarks, it seems that recording the data from content controls in the bookmarked sections (provided the content controls are uniquely named) is fairly simple using a collection to hold the names and values.
Thus you can recall the userform to add a section and retain the inserted content control values. It won't of course restore ad hoc text. If you want to edit the bookmarked texts you'll need to add the content controls to hold the edits to the data document. There are tools available from my web site to insert content controls easily and to ensure they are uniquely named.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 10-17-2018 at 05:03 AM. |
#10
|
|||
|
|||
Quote:
|
#11
|
|||
|
|||
Quote:
|
#12
|
||||
|
||||
Here is some aircode that might get you started. I'll assume that you use the checkbox Tag property to store the associated bookmark name
Code:
Dim aCtl as MSForms.Control For Each aCtl In Me.Controls Select Case TypeName(aCtl) Case "CheckBox" If ActiveDocument.Bookmarks.Exists(aCtl.Tag) then ActiveDocument.Bookmarks(aCtl.Tag).Range.Font.Hidden = Not aCtl.Value End If End Select Next aCtl
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#13
|
|||
|
|||
Quote:
Can you help me understand the code? Also, where in the code do I write the name of the bookmark associated? |
#14
|
||||
|
||||
Kate
You said you have a userform with checkboxes. In that userform, you can select a checkbox and see its properties in the Properties Window. There is a property called Tag. Set the value of this property to match the name of the bookmark which should show when that checkbox is ticked. The code I supplied should sit in the subroutine that runs when the user clicks a button to dismiss that userform (ie after they tick the checkboxes they want). The code loops through all the objects on the userform and if it finds a checkbox with a tag property that matches a bookmark that exists in the document, it either hides or shows that text based on the value of the checkbox.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#15
|
|||
|
|||
Quote:
I've added it to the code for the command button however it doesn't seem to have worked. The bookmarks are still there. I have attached the form for you to see. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Number every other page consecutively | fredhinke | Word | 1 | 11-11-2016 01:30 PM |
Import external font to Word document | Patrick_87 | Word | 3 | 07-17-2015 01:04 AM |
how to put three videos in PowerPoint 2013 and have them play consecutively | historyb | PowerPoint | 0 | 10-16-2014 11:42 AM |
number every second page consecutively | acrimin | Word | 7 | 06-05-2013 05:59 AM |
Automatically inserting information into report | joughin | Word | 3 | 05-15-2012 09:12 PM |