Using one WORD document for different audiences

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

I'm exploring the path where I use some VBA code to toggle text in my document (building on SNB's feedback).

Problem is that with the hidden text displayed, I can edit and change that but everything I do is not kept as it disappears the next time I toggle.
Seems the only way to change the advanced text is in the Alt-F9 mode where I display the field...
Now that is disappointing and cumbersome... Back to the paragraph style?

My document has this test field:

Code: Select all

{ IF {DOCVARIABLE  "EJH" } ="v" <hidden text and formatting here>" ""}
My VBA code looks like this (triggered by a button in the document):

Code: Select all

Private Sub EJH_Hide_Click()
    'One time use only to create variable EJH if it does not exist
    'ActiveDocument.Variables("EJH").Delete
    Dim oVars As Variables, D
    Set oVars = ActiveDocument.Variables
    On Error Resume Next
    D = oVars("EJH").Value
    If Err.Number = 5825 Then ActiveDocument.Variables.Add Name:="EJH", Value:="v"
    'Toggle (v=visible, h=hidden)
    If D = "v" Then
        D = "h"
        EJH_Hide.Caption = "Normal"
    Else
        D = "v"
        EJH_Hide.Caption = "Extended"
    End If
    'Apply
    With ActiveDocument
        .Variables("EJH") = D
        .Fields.Update
    End With
End Sub

snb
4StarLounger
Posts: 596
Joined: 14 Nov 2012, 16:06

Re: Using one WORD document for different audiences

Post by snb »

As I showed in the file I uploaded:

Code: Select all

Private Sub EJH_Hide_Click()
   with ActiveDocument.Variables("EJH")
       .value=iif(.value="v","h","v")
   end with
   activedocument.fields.update    
End Sub
There's no reason to add a new docvariable every time. Once added, a docvariable can't be removed manually. (BTW you can remove the Docvariable-Field, but that doesn't effect the Docvariable nor its value.
You can toggle between 'field editing mode' and 'reading mode' using Alt-F9.
The 'field editing mode' is 100% independent of the (in)visibility in 'reading mode'

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

I am not adding a new variable every time. It's just there to create it the first time (if it doesn't exist yet).

And yes, as I said, I seem to be able to only edit the information in the field in field editing mode. But if one has that off, it's very tempting to start making changes in the text you see (only to find out that everything you do is void and disappears without warning).

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

OK, so I created a special paragraph-style that (I hope) doesn't do anything but just servers as a marker.
This is how it looks now:
2024-04-11 12_33_18-Modify Style.png
If I apply this to text (and yes, I shouldn't use manual formatting but just use character- and paragraph-styles. I always used the latter but need to get used to character styles as well now), some of this seems to work.
But if I apply this style to a section my document that e.g. has headers, the headers disappear. Now that's NOT what I want.
So I think, there's still too much formatting in my style. It seems however I can't do less than this. What am I missing now?
You do not have the required permissions to view the files attached to this post.

User avatar
StuartR
Administrator
Posts: 12650
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Using one WORD document for different audiences

Post by StuartR »

You need to use a character style for this. Not a paragraph style
StuartR


User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

Ah... OK. I apolize. Will try

snb
4StarLounger
Posts: 596
Joined: 14 Nov 2012, 16:06

Re: Using one WORD document for different audiences

Post by snb »

it's very tempting to start making changes in the text you see (only to find out that everything you do is void and disappears without warning
That isn't correct; you must be making several mistakes doing this.

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

StuartR wrote:
11 Apr 2024, 11:59
You need to use a character style for this. Not a paragraph style
This time the heading styles survive, but the character style "Strong" (to make bold characters) is removed...
2024-04-11 18_15_49-Modify Style.png
You do not have the required permissions to view the files attached to this post.

User avatar
StuartR
Administrator
Posts: 12650
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Using one WORD document for different audiences

Post by StuartR »

That is correct, you can't have two character styles applied to the same text at the same time.
StuartR


User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

OK, so the fact that I hardly ever used character styles (but always use paragraph styles) actually helps me here ;-)

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

Picked this back up and exploring the option where I can set a character style to 'hidden' by clicking a button (which calls VBA code).
I also added a background color to highlight the hidden text so when I edit the document I can see in which part I'm doing that.
New question: how do I remove the hidden text from the TOC? I think I need more VBA code for that

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15716
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Using one WORD document for different audiences

Post by ChrisGreaves »

ErikJan wrote:
24 Apr 2024, 10:13
... I can set a character style to 'hidden' by clicking a button (which calls VBA code).
Hi ErikJan. This seems to be getting awfully complicated for what ought to be a simple solution.

(1) I have oft been frustrated with using {IncludeText} (and today I see in Word2003 the {REF} field which I think I have never used.)
(2) I have mainly used the {IncludeText} field to insert an entire training module into an all-singing all-dancing customized training manual for a client's five-day course.
(3) I too found a difficulty in making edits to included text. Right up to the time I stopped paid work, I could not find a simple way to, say, right-click on included text and get my VBA code to open the included text document file for editing. Let alone the text that appeared in that included text from a lower-level {IncludeText}. (I felt that I should be able to construct a training manual the way that I construct programs - by using pre-tested components)
(4) That I can, using VBA code, edit Included-from-file images makes the task even more frustrating:-
Untitled.png
(5) Using Paragraph and/or Character styles is another issue
(6) Using Paragraph and/or Character styles under switch control (in your case "make it [in]visible") is another issue.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.
By definition, educating the client is the consultant’s first objective

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

Chris,

Thanks for the response but I miss your point. Are you suggesting I should approach this differently?
I'm currently sort of happy with what I have now. The document has a button that with hide or unhide the 'special' sections.
I know that I can set hidden text not to print (or export: it's not exported in a PDF as well).
All I'm looking for now is a trick to hide this text (if hidden) from the ToC. If I find a way to do that, I can add that to the code so it does that when I switch between hidden/not hidden (and then of course, I update the ToC if needed as well through VBA)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15716
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Using one WORD document for different audiences

Post by ChrisGreaves »

ErikJan wrote:
24 Apr 2024, 13:08
Thanks for the response but I miss your point. Are you suggesting I should approach this differently?
Hi ErikJan. Don't worry about missing my point; I often miss it myself.
I posted because of a vague unease I have that what ***I*** think should be a simple exercise ("hide text using a switch") looks as if it is developing into a major solution.
That's why I said that I'd faced much the same problem for twenty years - an independent operation on Included text - in your case hiding text AND editing the source of the included text.

I don't have a simple solution for your problem.
But I do worry that it appears to be building up a lot of "stuff".

I still have a feeling that if I was better at {field codes} I'd have a nifty solution with {IF} and {INCLUDETEXT}
I'm currently sort of happy with what I have now. ... All I'm looking for now is a trick to ...
This too sets off alarm bells: "It just needs one more grommet hooked through the left-handed blivot and then ..."

Cheers, Chris
By definition, educating the client is the consultant’s first objective

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

Made me think about this Chris ;-)
https://www.youtube.com/watch?v=Ac7G7xOG2Ag

User avatar
HansV
Administrator
Posts: 78788
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Using one WORD document for different audiences

Post by HansV »

:rofl:
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

I think I got a solution for the ToC!

I now use Heading levels 1-4. I changed Heading levels 5-8 to be based on 1-4.

Then I start to use Heading levels 5-8 for the additional / extended paragraphs.

Next, remember that I use a button that calls VBA code which makes text in the Character style that I use for the extended sections hidden or not hidden.
In that same code, I will now try to add code that shows a ToC with Heading levels only from 1-4 or a ToC with headinglevels from 1-8 (for the extended view), then I re-create the ToC each time.

I'll let you know if I can get that to work.

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

It's working! I'm optimizing the code now and will share later

User avatar
Charles Kenyon
5StarLounger
Posts: 640
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Using one WORD document for different audiences

Post by Charles Kenyon »

I was just viewing this again. Not sure if the point was made that hidden text is still there.
People receiving the document will be able to view it.
Convert to pdf or actually delete the text if you want it gone.

User avatar
ErikJan
BronzeLounger
Posts: 1287
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Using one WORD document for different audiences

Post by ErikJan »

Yes, the idea was and is that versions for distribution are exported as PDF, therefore all hidden text is gone from these files.
I just discovered that tables with hidden text are empty, but the tables themselves regretfully survive (the lines around them are still visible... and/or the space the table takes). I don't think there's a solution for that...