Changing the text within a header
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Changing the text within a header
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
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Changing the text within a header
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.
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.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
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.
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Changing the text within a header
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.
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
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
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. Sometimes I get some gibberish (Computer lingo) in text boxes
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. Sometimes I get some gibberish (Computer lingo) in text boxes
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Changing the text within a header
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
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
Hi Hans
I have attached a stripped down copy of document
I have attached a stripped down copy of document
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Changing the text within a header
In a quick test I haven't been able to reproduce the problem.
I'll test some more later on.
I'll test some more later on.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
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
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Changing the text within a header
By the way, you have protected the VBA code with a password, so I can't take a look at that.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
I just relized that and made a Protection Password FREE document
You do not have the required permissions to view the files attached to this post.
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
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
To
And problem seems to be gone, everything seems to work
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")
Code: Select all
On Error Resume Next
txtSubject = ActiveDocument.Variables("Your company name")
txtInfo = ActiveDocument.Variables("Your clients name")
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
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.
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.
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Changing the text within a header
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.
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
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Changing the text within a header
Thank you Hans for all of your assistance