Forum Discussion
templatebuilding
Magnus_Edstrm I have added a second "form" for the Välj Ärendetyp item in the Arende combobox and I have also made the necessary modifications to the code to deal differences between the list items and what can be used as the bookmark in the document.
The code is now
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim BMName As String
With ContentControl
If .Title = "ärende" Then
For i = 1 To .DropdownListEntries.Count
BMName = LTrim(Mid(.DropdownListEntries(i).Text, InStrRev(.DropdownListEntries(i), " ")))
If ActiveDocument.Bookmarks.Exists(BMName) Then
ActiveDocument.Bookmarks(BMName).Range.Font.Hidden = True
End If
Next i
For i = 1 To .DropdownListEntries.Count
If .DropdownListEntries(i) = .Range.Text Then
BMName = LTrim(Mid(.DropdownListEntries(i).Text, InStrRev(.DropdownListEntries(i), " ")))
If ActiveDocument.Bookmarks.Exists(BMName) Then
ActiveDocument.Bookmarks(BMName).Range.Font.Hidden = False
End If
End If
Next i
End If
End With
End Sub
- Magnus_EdstrmDec 30, 2022Copper ContributorHi Doug. Actually it is possible to do and It was very simple. I went through the list and manually moved each table to the same location on the paper i e "stacked" them ontop of eachother. Granted when all are displayed it looks aweful but it works like a charm.
/Magnus - Dec 30, 2022
That will not be possible with the arrangement that you now have.
That does not however mean that it cannot be done. One way would be to have the tables in another document, identified by their bookmarks, and have code access that the relevant table in that document and copy and paste it into the required position in the host document. - Magnus_EdstrmDec 29, 2022Copper ContributorSo now I only have one more issue. I would like the tabels to appear at the top of the page right below the line regardless of which table it is. How do I do that?
- Magnus_EdstrmDec 29, 2022Copper ContributorHey Doug, I have now checked for discrepancies both in the bookmarks and the list and I am happy to report that it is all working flawlessly.
Thank you so much for your help on this. One thing that is clear to me in all of this, is that I need to learn VB coding *L*. - Magnus_EdstrmDec 29, 2022Copper ContributorThank you for your patience with me on this Doug, It´s not easy being a noob *L*
- Magnus_EdstrmDec 29, 2022Copper Contributor
- Dec 29, 2022
You need to check for discrepancies between the items in the dropdown list (as parsed) and the bookmark names.
For example there is nothing in the dropdown list that correspondes to the bookmark highlighted in yellow
When "välj ärende" is selected with hidden text not displayed, the items highlighted in yellow
no longer appear
- Dec 29, 2022It sounds like you have hidden text being displayed!!!
- Magnus_EdstrmDec 29, 2022Copper ContributorThe issue is that all fields are visible when "välj ärende" is selected in the list and there is no change when I select a different line in the list. so ie. nothing happens what so ever.
- Dec 28, 2022As there is no bookmark with the name of ärende, there will be nothing visible when that is selected.
As a test, if you insert a bookmark with the name of ärende around something, when you select välj ärende, the text identified by that bookmark should be visible and everything else should be hidden. - Magnus_EdstrmDec 28, 2022Copper ContributorI the script is workning properly then when the list option "välj ärende" is selected (default selection) then all tables should be hidden correct?
- Magnus_EdstrmDec 28, 2022Copper ContributorOk, that is what I figured. I opened your modified file but no difference on my end.
- Dec 28, 2022
Magnus_Edstrm The entries in the list can contain those characters, but the bookmark names cannot ad therefore, the code removes those characters so that the resulting strings matchs the bookmark names
- Dec 28, 2022
Magnus_Edstrm To get it to work, I had to remove the check mark from the MISSING: Ãrendemall MBL samfak.dotm under Tools>References in the Visual Basic Editor. I have attached the amended file.
- Magnus_EdstrmDec 28, 2022Copper Contributor
I have tried to make the bookmarks as instructed and no joy I´m affraid. I can´t seem to grasp what I am doing wrong. I´ll attach the file to this reply so you can see where I´ve gone wrong.
Thank you so much for your patience Doug
/Magnus
- Magnus_EdstrmDec 28, 2022Copper ContributorSo if I understand you correctly the listnames can include those characters and spaces and the script removes them when searching for a correlating bookmark.
- Dec 28, 2022The code that I gave you parses each of the list items to result in a string that can be used as the bookmark name. The result of that parsing will be a string from which the first three characters are omitted and all of the spaces, §, -, and / have been removed. The bookmark names need to match the resulting strings.
- Magnus_EdstrmDec 28, 2022Copper ContributorHi Doug
I have tried to adapt the list and bookmarks with no luck. In the list properties is it the name or value that needs to correlate with the listed name of the bookmark? - Dec 27, 2022
Magnus_Edstrm There needs to be a way of matching the bookmark names to the items in the dropdown list.
In the code posted below, the following commands:
BMName = Replace(Mid(.DropdownListEntries(i).Text, 5), " ", "")
BMName = Replace(BMName, "§", "")
BMName = Replace(BMName, "-", "")
BMName = Replace(BMName, "/", "")- strip the first four characters (shaded in yellow in the screenshot) from each item in the list and remove all of the spaces from the remainder of the item
- remove the §
- remove the -
- remove the /
so that an item such as:
§19 Information Om undantag från utlysning AF § 6
would be reduced to:
InformationOmundantagfrånutlysningAF6
which complies with the limitations for the names of bookmarks
So, if you delete all of the existing bookmarks and replace them with bookmark names such as
InformationOmundantagfrånutlysningAF6
the code will work as required.
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim BMName As String With ContentControl If .Title = "ärende" Then For i = 1 To .DropdownListEntries.Count BMName = Replace(Mid(.DropdownListEntries(i).Text, 5), " ", "") BMName = Replace(BMName, "§", "") BMName = Replace(BMName, "-", "") BMName = Replace(BMName, "/", "") If ActiveDocument.Bookmarks.Exists(BMName) Then ActiveDocument.Bookmarks(BMName).Range.Font.Hidden = True End If Next i For i = 1 To .DropdownListEntries.Count If .DropdownListEntries(i) = .Range.Text Then BMName = Replace(Mid(.DropdownListEntries(i).Text, 5), " ", "") BMName = Replace(BMName, "§", "") BMName = Replace(BMName, "-", "") BMName = Replace(BMName, "/", "") If ActiveDocument.Bookmarks.Exists(BMName) Then ActiveDocument.Bookmarks(BMName).Range.Font.Hidden = False End If End If Next i End If End With End Sub
You can add anything that is required within each bookmark.
- Magnus_EdstrmDec 27, 2022Copper Contributor
I have completed the template as I would like it to be. Can it work like this or are there issues that make it impossible to run the script correctly?
/Magnus
- Magnus_EdstrmDec 27, 2022Copper ContributorOk, so I am now at the point where the two initial fields work with the script. How do I add additional fields and have the script work for these aswell?. Also I want to create textfields in the tables to promt the user to fill in the information associated with the heading, can I just add these in the table without it screwing up the script?
- Dec 22, 2022Certainly, the display of hidden text must be turned off for it to work.
I would suggest that you download another copy of the document that I uploaded and via File>Opions>Advanced>Show document content, you turn on the display of bookmarks and be very careful not to delete them. - Magnus_EdstrmDec 22, 2022Copper ContributorOk, so as the noob I am I had the "show hidden characters" enabled. As I turned it off I managed to make both forms disappear when the combobox was set to "välj ärende" and when I changet that to "Information om verksamhetsförändring" the for table for "Förhandling om verksamhetsförändring" showed up. Now I can´t seem to get it to work (I may have deleted some bookmarks for the textfields I added to the table form if that can cause it to not work?)
- Magnus_EdstrmDec 22, 2022Copper ContributorI am trying with the document you uploaded. It´s kinda hard to troubleshoot since I don´t know the first thing about "how" it works *S*
- Dec 22, 2022Are you trying with the modified document that I uploaded or another document?