Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding text & formatting using code (Word 2000 sp3)

    I want to be able to add text to a document at the place where the cursor is. Some of the text entries are titles such as 'Background:' and 'Comments:' other text has been entered via a userform, such as 'MeetingName' and 'AgendaItem'.
    I also want to apply formatting such as bold and centre to some the text. The same text and layout has to be placed on a number of different pages so I plan to have the code attached to a button on the menu bar. What is the best way to have code enter the information in a document?

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding text & formatting using code (Word 2000 sp3)

    The general idea is to store the text you want to insert in a public variable of type String, say strText, and use Selection.TypeText to insert it into the document at the insertion point:

    Public Sub InsertText()
    Selection.TypeText strText
    End Sub

    But it is not clear to me how you want to determine which text should be inserted, and how to determine what should be made bold etc. Macro code cannot guess your intentions, so you will have to provide very exact information.

  3. #3
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding text & formatting using code (Word 2000 sp3)

    Thanks Hans
    I have attached a Word doc which shows the layout that I require and how I plan to get the information from the user. The layout is the same every time I start a new Brief. The only information that varies from Brief to Brief is the 'Item No.' and its 'Title', so I thought that using an input box would be the easiest way to get that information.
    Attached Files Attached Files

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Adding text & formatting using code (Word 2000

    If the information is to be the same in various places and you would like to be able later to change it through a single interface, then you might want to use a field which refers to a variable or document property. Please see the example Hans posted in <post#=259,183>post 259,183</post#>.

    Added: I forgot to mention... metadata cleaners often will remove custom document properties and document variables, on the theory that they probably were private data you did not intend to share with the recipient. Unless you have locked the fields, the recipient's printout may be littered with errors when those fields discover that the underlying values were deleted. If you think this might be an issue, you can add a "finalize fields" option to your toolbar.

  5. #5
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding text & formatting using code (Word 2000

    Thanks for the information

    The document variables are working ok. In relation to metadata cleaners, how do I lock the document variables?

    Regards

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding text & formatting using code (Word 2000

    a) Do you you use metadata cleaners in your company?
    [img]/forums/images/smilies/cool.gif[/img] If so, check whether they actually remove document variables. For example, the option 'Remove personal information from file properties on save' available in Word 2002 and 2003 doesn't do that.
    c) I don't think you can lock document variables. Jefferson meant that you can lock the DocVariable fields in the document: if you select some text and press Ctrl+F11, all fields within the selection will be locked, i.e. they won't be updated when you press F9 or print the document. You can also unlink fields (i.e. replace them with their results) by pressing Ctrl+Shift+F9.

  7. #7
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding text & formatting using code (Word 2000

    Thanks Hans
    I'm still experimenting with document variables in the headers, footers and body of the document and will check the metadata cleaner I have at work after Easter.

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •