Changing the text within a header

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Changing the text within a header

Post by ABabeNChrist »

Is it possible to change the text within a header using a bookmark and an input box. I am trying to figure out a way that i can change the text within a header using code that would assist others using this document, that have little to no computer skills, to be able to make these changes

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

Re: Changing the text within a header

Post by HansV »

One way would be to insert an ASK field in the document and a bookmark that refers to the bookmark defined by the ASK field. Downside is that the user can very easily delete the ASK field accidentally when editing the document.

Another option (which I prefer) is to use a userform to ask for information. I have attached a (zipped) template that I once posted in Woody's Lounge. When you create a new document based on the template, the userform will be displayed automatically (if macros are enabled). The information entered by the user is used to populate the header. The dialog can be displayed at any later time by pressing Alt+Shift+V.
Test.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

I was checking out the attached file and I like the way it populates the data that is entered using the userform. I made some small changes to suit my needs. Except I was unable to figure out a way to eliminate the title “Subject:” . I would use this section for entering only a company name.

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

Re: Changing the text within a header

Post by HansV »

The text "Subject:" is fixed text in the header.
First press Alt+F9 so that you can see field codes.
Double-click in the header to activate it; you can then edit the text as needed.
Double-click in the body of the document when you're done, and press Alt+F9 to hide the field codes.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

Hi Hans
I made some a couple small changes to the userform, added code to tool bar to open userform if needed and made the changes to the fixed text within the header. Everything seems to work great; except when I reopen the document and select to open userform from tool bar this is how the user form reappears. This only happens when document / userform is reopened.
userform view.JPG
Sometimes I get some gibberish (Computer lingo) in text boxes
gibberish.JPG
You do not have the required permissions to view the files attached to this post.

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

Re: Changing the text within a header

Post by HansV »

What exactly did you change? It looks like the text boxes are being filled with something entirely different from the original content.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

Hi Hans
I have attached a stripped down copy of document
Copy of REl 7A-1 Part 2.docm
You do not have the required permissions to view the files attached to this post.

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

Re: Changing the text within a header

Post by HansV »

In a quick test I haven't been able to reproduce the problem.

I'll test some more later on.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

I also observed that even thought it appears that the text within the header says one thing, when viewed in print preview it shows the same text or gibberish that was replayed in userform

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

Re: Changing the text within a header

Post by HansV »

By the way, you have protected the VBA code with a password, so I can't take a look at that.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

I just relized that and made a Protection Password FREE document :clapping:
Copy of REl 7A-1 Part 2.docm
You do not have the required permissions to view the files attached to this post.

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

I believe I found my problem. When I removed the visible text Subject and Info from the header. This is when my problem seemed to occur.
So then I changed the code within the userform from

Code: Select all

    On Error Resume Next
    txtSubject = ActiveDocument.Variables("Subject")
    txtInfo = ActiveDocument.Variables("Info")
To

Code: Select all

  On Error Resume Next
  txtSubject = ActiveDocument.Variables("Your company name")
  txtInfo = ActiveDocument.Variables("Your clients name")
And problem seems to be gone, everything seems to work :crossfingers:

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

Re: Changing the text within a header

Post by HansV »

OK, let me know if new problems surface.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

Hi Hans
I thought the problem was gone, I was wrong; I overlook one area, Print preview at the opening of document. When I now first open document and select Header data from the tool bar, that gibberish I mention earlier is gone and from looking at the document upon first opening every things seem fine too, until you use print preview, then you see the gibberish and when you return to normal view all that gibberish is now visible in the header. I did notice that when you make changes using the user form everything seems to work fine.

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

Re: Changing the text within a header

Post by HansV »

When I open the document that you attached most recently (with unprotected VBA code), I do indeed get gibberish when I display the userform. But once I enter a name for the company and client, I can display the userform, print preview, save, close and reopen the document any number of times and the names will be exactly as I entered them.
I'm afraid that, just as with your problem with corrupted workbooks, I have no idea what causes this - it appears to be specific to your computer.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Changing the text within a header

Post by ABabeNChrist »

Thank you Hans for all of your assistance