Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Preview an auto-text entry in a user form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
amanda taylor - 20 May 2008 07:04 GMT
I have template with lots of clauses saved as auto-text entries.  I have a
user form with checkboxes so that users can select which clauses they want
and then insert them all at once.  
I would like users to be able to preview the clause to see if they want to
insert it.
Is there any way to create a similar preview window as in the auto-text
dialog box in my userform?
Thank you

url:http://www.ureader.com/gp/1023-1.aspx
Jean-Guy Marcil - 20 May 2008 13:52 GMT
> I have template with lots of clauses saved as auto-text entries.  I have a
> user form with checkboxes so that users can select which clauses they want
[quoted text clipped - 4 lines]
> dialog box in my userform?
> Thank you

If all you want is display the autotext text (no formatting), then use a
textbox or a label and this code in the appropriate event:

With Me
   .Label1.Caption = NormalTemplate.AutoTextEntries("aero_header").Value
End With

But this will display field codes and other funny characters...
So, if you want to display field values instead of code, try this instead:

Dim rngAuto As Range

Set rngAuto = ActiveDocument.Range

With rngAuto
   .Collapse wdCollapseEnd
   .InsertAfter "aero_header"
   .InsertAutoText
End With

With Me
   .Label1.Caption = rngAuto.Text
End With

rngAuto.Delete

However, if you want to display the AutoText with the formatting, you will
need a RichTextBox control.
Add it to your Toolbox palette by right clicking on the control palette when
you are designing the userform. Check the "Microsoft RichTextBox COntrol 6.0"
in the list. It will be added to your palette. If, when you try to add it to
your userform, you get a trust message, then, in order to get your machine to
accept the ActiveX control, see the following post (it is about Excel, but it
still applies...)

http://groups.google.com/group/microsoft.public.office.developer.vba/browse_thre
ad/thread/3ef04a2f2a8cef1e/76252635e022bb41


After that, add the RichTextBox comntrol to you userform. Finally, at the
appropriate location in your code, use code like this:

Dim docAuto As Document
Dim rngAuto As Range

Set docAuto = Application.Documents.Add
Set rngAuto = docAuto.Range

With rngAuto
   .InsertAfter "AutoText_Name"
   .InsertAutoText
End With

docAuto.SaveAs "C:\My Documents\Test\TestAuto.rtf", wdFormatRTF
docAuto.Close

With Me
   .RichTextBox1.FileName = "C:\My Documents\Test\TestAuto.rtf"
End With

The only way I know of getting a RichText box to display the formatting, is
to feed it an RTF file. You can use this code over and over, the RTF file
gets re-written each time...
Jules - 22 May 2008 12:20 GMT
Jean-Guy
Would you mind providing a sample of how to apply the RTF code in the
userform properly.
I've a userform and RTF control no problem and a Cmd Button. I assume I
still need a label field. (I use Richtext Control for another of my
templates) but I don't see the reference to the source autotext template and
how the user's choice sends the Autotext to the RTF file which is then
reloaded and dumped in the Word doc? I'm a bit confused, is that how it is
supposed to work? I am using Word 2007 (have 2003 also)

Thank you (Merci)

>> I have template with lots of clauses saved as auto-text entries.  I have
>> a
[quoted text clipped - 75 lines]
> to feed it an RTF file. You can use this code over and over, the RTF file
> gets re-written each time...
Jean-Guy Marcil - 22 May 2008 13:23 GMT
> Jean-Guy
> Would you mind providing a sample of how to apply the RTF code in the
[quoted text clipped - 5 lines]
> reloaded and dumped in the Word doc? I'm a bit confused, is that how it is
> supposed to work? I am using Word 2007 (have 2003 also)

Read my post again.
I mention the label only if you want to display the text from the autotext
wihtout any formatting.

If you want to dislay it within a RichTextBox, then you do not need a label.
You have to choose which one you want to do.
try both and see which one best suits your purpose.

For the RichTextBox I did post the following:


> > Dim docAuto As Document
> > Dim rngAuto As Range
[quoted text clipped - 13 lines]
> >    .RichTextBox1.FileName = "C:\My Documents\Test\TestAuto.rtf"
> > End With

You just need to call this code wherever appropriate on your userform.
You stated you already had checkboxes listing the autotext names.
I guess you could add a "Display" command button next each one to give users
the option to see the autotext...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.