Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding text to Header (VBA(JScript)/Word/2000)

    Hello Lounge,

    I am trying to put the follow info in the header:

    Left Middle Right
    Name Page# Date

    I am working with JScript to create an activexobject with is an automation object so that I can access the word object model. I have been able to access the headerobject and I have been able to enter the name via range.insertafter and the pagenumber via the headers(1).pagenumbers.add() method. The problem I am having is putting the date in the right hand corner. How do I get my range over to the right hand corner. I have tried the range.setrange() method, range.expand() method and when I do the range does not change. After I insert the name text, the range then increases in size. Can a range be increased in size only if there is already text in the header? Is there a way for me to get the end of the line so I can do a range.insertbefore? How do I get a selection object from the headers(1).range object? I have included my code below for reference. Although it is JScript it is the same as VBA in terms of the object model. Also, I have passed in the number values for the constants because the browser does not have the constants defined. Thanks for any help in helping me understand the range/selection objects as I am newbie to VBA.

    ju

    function startWord(strFile)
    {
    var myApp = new ActiveXObject("Word.Application");

    if (myApp != null)
    {
    //Open word on client machine
    myApp.Visible = true;

    //Pass the webpage by URL to word
    var worddoc = myApp.Documents.Open(strFile);

    //Get the header range
    headerRange = worddoc.sections(1).headers(1).range;

    //Set the font characterstics of the header range
    headerRange.font.name = "Bookman Old Style";
    headerRange.font.size = "12";

    //Pass the name
    headerRange.insertafter("Re:" + document.forms[0].RTF_Claimant.value);

    //Add the pagenumber to the header and make sure the header does not appear on the first page
    worddoc.sections(1).headers(1).pagenumbers.add(1,f alse);

    // NOW THIS IS WHERE I DO NOT KNOW HOW TO GET TO THE END OF THE LINE TO INSERT THE DATE
    // I HAVE TRIED DIFFERENT RANGE METHODS BUT THEY DO NOT GO PAST THE NAME I HAVE ALREADY INSERTED

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Adding text to Header (VBA(JScript)/Word/2000)

    Try something like
    worddoc.sections(1).headers(1).range.InsertAfter Chr$(9) & Date()

    The header should have a right aligned tab and Chr$(9) should give you a Tab character to move you across there

    StuartR

  3. #3
    New Lounger
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding text to Header (VBA(JScript)/Word/2000)

    Thanks Stuart. That did it. I think I understand ranges in word better now. Now I can go back and if I get the header range, it will be the length of the range I just created. Initially, the range is only one character length in the header when it is initially empty. Cool.

    JU

Posting Permissions

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