Results 1 to 15 of 15
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert autotext works on some pcs not others

    HI all
    VBA - W97

    I have code which inserts autotext into a documents header.
    On some pcs when I run code it inserts the autotext entry.
    On other pcs(users) when testing it doesnt insert the autotext entry.

    Sample of code below:
    x = current section number

    'perform formatting of 1st page header
    'set range as header 1st page
    Set rngHeader = ActiveDocument.Sections(x).Headers(wdHeaderFooterF irstPage).Range

    'check if logo is already in header - if found no need to insert company logo
    If rngHeader.InlineShapes.Count > 0 Then
    blnLogoFound = True

    Else
    'else if no logo found in header - add logo
    'if section is not the 1st section in document
    'unlink to previous section
    If x <> 1 Then
    With ActiveDocument.Sections(x)
    With .Headers(wdHeaderFooterFirstPage)
    .LinkToPrevious = False
    End With
    End With
    End If

    'call HeaderSetUpFirstPage to format
    Call HeaderSetUpFirstPage
    End If

    Function HeaderSetUpFirstPage
    rngHeader.Text = strHeader1stPage
    rngHeader.Select
    rngHeader.InsertAutotext

    'other code here
    End Function

    Previously the autotext entry was designed as WordArt in Word 97.
    Due to limitation of w97 I then redesigned autotext in W2000.
    When autotext was in W97, the autotext was inserted & there were no problems.
    Since autotext has been in W2000 thats when I noticed error.
    Note:All users have word/office 97.

    Does anyone know if this could be some setting or configuration on the users pcs which is resulting in the autoText being inserted in some of the pcs & not others.
    Any suggestions would be mostly appreciated.
    Thanks Diana

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Insert autotext works on some pcs not others

    Hi Diana,

    The "InsertAutoText" method is probably what's giving you trouble - have to admit I wasn't even aware this method existed, but in any case it's an imprecise method since you can't explicitly specify which autotext entry you want to insert.

    The more precise method would be to use to "AutoTextEntry object Insert" method; here's an example:

    <pre>ActiveDocument.AttachedTemplate.AutoTextEntri es("YourAutoText").Insert Where:= _
    Selection.Range, RichText:=True
    </pre>

    In this example, the autotext is stored in the active document's attached template - the other issue you need to consider is: where are you storing the autotext?

    Gary

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert autotext works on some pcs not others

    Hi Gary

    FOr working with headers in doc - I define a header range & work with the range.
    As I thought it would be easier to work with a range.
    I could only insert auotext in a range by using the following syntax:

    rngHeader.InsertAutotext

    Thats why I used.

    Storage of autotext entry.
    IS stored in a global template which holds all global company autotext entrys.

    Cheers Diana

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Insert autotext works on some pcs not others

    Fair enough.

    Now, since the previous line of code you've got, before:

    rngHeader.InsertAutotext

    is:

    rngHeader.Select

    - you do have a Selection object - that should permit you to use the method I suggested. Give it a try and let me know...

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: On second thought....

    Since you mentioned the autotexts are in a global template....

    The AutoTextEntry object Insert method I suggested does have the limitation that the autotext entry must be in either the Normal template or the attached template. It does not work directly if the autotext entry is in a global template.

    There is a workaround for that (somebody had posted code for it on the old Lounge). The workaround involves saving the pathname for the current attached template to a variable; then temporarily attaching the global template as the attached template (update styles = False); do the AutoText insert; then reattach the original template.

    Even though this involves more steps, it provides the precision of being able to refer to the autotext entry by name. If you're interested I can provide code for the above workaround.

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: On second thought....

    Gary

    I forgot to mention that in another function I set the autotext name as the autotext varies depending on conditions.
    The value is stored in string strHeader1stPage.

    Yes I would be interested in workaround code so I can implement & test.
    Thanks Diana

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: On second thought....

    Here's a recreation of that general idea. This should work fine but do note that I haven't tested this:

    <pre>Public Sub InsertAutoTextFromGlobalTemplate()
    Dim objCurDoc As Document
    Dim strAttTemplateName As String

    Set objCurDoc = ActiveDocument
    With objCurDoc
    strAttTemplateName = .AttachedTemplate.FullName
    '
    .UpdateStylesOnOpen = False
    .AttachedTemplate = "path for your global template"
    '
    .AttachedTemplate.AutoTextEntries(strHeader1stPage ).Insert Where:= _
    Selection.Range, RichText:=True
    '
    .UpdateStylesOnOpen = False
    .AttachedTemplate = strAttTemplateName
    End With

    End Sub
    </pre>

    Gary

  8. #8
    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: On second thought....

    I think this syntax will also work (assuming the template is loaded):

    Dim intTemp As Integer
    For intTemp = 1 To Templates.Count
    If LCase(Templates(intTemp).Name) = "myGlobal.dot" Then
    Selection.TypeText Templates(intTemp).AutoTextEntries("strHeader1stPa ge").Value
    End If
    Next

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: On second thought....

    That's an interesting one; didn't know you could do that!

    But still, this limits you to a text string; if the autotext has associated styles, formatting, graphics, tables etc. they're not going to come across this way.

    I gathered from the original post, that the autotext contained a Word Art object (despite having the name "strHeader1stPage" <g>); if you try to return the value of an autotext object that is a graphic, will it return any usable result or will it cause a runtime error? (I initially typed "rumtime error", hmm - I suppose that could occur if the template is loaded!)

  10. #10
    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: On second thought....

    You're absolutely right. That kills the rich text. This should work:

    Dim intTemp As Integer
    For intTemp = 1 To Templates.Count
    If LCase(Templates(intTemp).Name) = "myglobal.dot" Then
    Templates(intTemp).AutoTextEntries("strHeader1stPa ge").Insert _
    Where:=Selection.Range, RichText:=True
    End If
    Next

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: On second thought....

    Haven't had a chance to test it yet, but if this method works, that's great, since it avoids the whole need for the attach/detach etc. routine.

    If you have a global template in the Startup directory, and are reasonably sure that it's going to be loaded, then you should be able to omit looping through the Templates collection, and simply address the global template by name, along the lines of:

    Templates("myglobal.dot").AutoTextEntries("ATEntry ").Insert etc.

    Maybe just do a test first to confirm that myglobal.dot is currently loaded.

    This is one of those things that seems so straightforward, one wonders why this wasn't suggested sooner (assuming it turns out that it works! <g>)

  12. #12
    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: On second thought....

    > you should be able to omit looping through the Templates
    > collection, and simply address the global template by name

    I think I tried that first and couldn't make it work. The whole use of text and numeric indexes in collections seems very inconsistent. But that's the view from the shop floor; I'm sure it all makes sense in the executive suite.

  13. #13
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: This Works

    It works if you refer to the global template by its full path:

    <pre>Sub InsertATEFromGlobal()
    Const GLOBAL_FULLNAME As String = "D:WordDataTemplatesMeGlobalAutotextHolder.dot "
    '
    If AddIns(GLOBAL_FULLNAME).Installed Then
    Templates(GLOBAL_FULLNAME).AutoTextEntries("ATE1") .Insert _
    Where:=Selection.Range, RichText:=True
    End If
    End Sub
    </pre>

    This seems like a really useful method we've arrived at, as it enables you to store all your autotexts in a single global template and easily access them.[img]/w3timages/icons/trophy.gif[/img]

  14. #14
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: On second thought....

    Gary

    'I gathered from the original post, that the autotext contained a Word Art object (despite having the name "strHeader1stPage" <g>);'

    the autotext entries inserted varies depending on certain conditions.
    Orginally the autotext were text strings.
    Furhter along in the project the specs 'evolved' to include some wordArt objects.

    Therefore left variable name "strHeader1stPage" as is.
    I thought name was suitable as there are autotext entries to go in words document layout - different first page
    and autotext entries to go into words standard headers -
    <strHeader2ndPage>.

    All autotext entries are stored in a global template.
    The variable "strHeader1stPage" is not a global variable only used privately.

  15. #15
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: On second thought....

    Hi,

    I kinda figured that's how Word Art object had ended up with a "str" prefix.

    Only the mildest of digs was intended - the point being that using a prefix reserved for a certain data type (in this case a string), for a different data type (in this case an object), is only going to lead to confusion.
    If the type of data being stored in the variable changes, then change the prefix. Or maybe use "var" to hedge your bets.

Posting Permissions

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