Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Apr 2002
    Location
    Christchurch, New Zealand
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA Code for Inserting AutoTextEntries (Word97)

    I have designed a Form within VBA for the user to fillin the blanks. I have an option button which if True I would like an auto text entry inserted into my document. The code I am using is

    If OptLoanTypeN.Value = True Then
    ActiveDocument.AttacheTemplate.AutoTextEntries ("Disclosure").Insert
    Where = ActiveDocument.CustomDocumentProperties ("Disclosure").Range.
    End If

    I would appreciate any help....

    Thanks

    EnglishRose

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

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    ER,

    The code you've posted definitely won't run. The "Where" named argument of the Insert AutoTextEntry method requires a valid range i.e. that is somewhere in the document itself.
    "ActiveDocument.CustomDocumentProperties("Disclosu re").Range" does not return a valid document range (unclear what you are trying to do here).

    It would be more typical to see code like this:

    If OptLoanTypeN.Value = True Then
    ActiveDocument.AttachedTemplate.AutoTextEntries("D isclosure").Insert , _
    Where:=Selection.Range
    End If

    - Then the remaining question is: what are you attempting to do with the custom document property, that we need to account for?

    Gary

  3. #3
    New Lounger
    Join Date
    Apr 2002
    Location
    Christchurch, New Zealand
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    Thanks for replying to my post.

    I have used CustomDocumentProperties for insertion of text into my document. I have used this instead of Bookmarks. Therefore, we need to identify this in the "Where".

    I have tried the code you have given me and this doesn't seem to be working either.

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

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    Hi again,

    You can use the value of a custom document property, and insert this as text into your document, for example:

    Selection.TypeText Text:=ActiveDocument.CustomDocumentProperties("Dis closure").Value

    or with a bookmark:

    With ActiveDocument
    .Bookmarks("bmkDisclosure").Range.Text = .CustomDocumentProperties("Disclosure").Value
    End With

    But a Custom Document Property cannot have a Range property as in your first code example.

    Can you sketch out in words, what you're trying to get inserted into the document? - there's an autotext entry and a custom document property in the picture, but it's unclear what you are trying to do with them.

    Gary

  5. #5
    New Lounger
    Join Date
    Apr 2002
    Location
    Christchurch, New Zealand
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    Ok, I have a document which has different clauses for different types of loans. I am have created a user form which contains fields for name, address etc etc this form also contains 3 option buttons 1 = Loan Type New, 2 = Loan Type Renewal & 3 = Loan Type Additional. What I am wanting to do is if the Loan Type New button is selected a clause is inserted where indicated within the document itself.

    Rather than using bookmarks to mark where text should be inserted I have used the custom document properties from within FilePropertiesCustom. For example this custom property is called "Disclosure".

    I have set up an auto text called "Disclosure" which contains the clause I require.

    I am wanting to write code which explains if the Option Button for Loan Type N is selected then add the disclosure (auto text) in the appropriate place (where the custom property "Disclosure") is placed in the document. If the Option Button for Loan Type R Or N is selected then do not insert this auto text entry.

    Hope this explains it better, I am just a beginner at VBA. Thanks heaps.

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

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    This sounds like a good setup and everything makes sense to me except the part where you are using a custom document property to mark where text should be inserted, rather than a bookmark - that is where I'm getting lost. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>. This is something with which I'm unfamiliar - how are you using a custom document property to mark a location in the document? - do you mean you are using a DocProperty field?

    If you can use a bookmark to mark a location in the text, then it gets easy:

    [code written into this window so not tested]
    ActiveDocument.AttachedTemplate.AutoTextEntries("D isclosure").Insert, _
    Where:=ActiveDocument.Bookmarks("bmkDisclosure").R ange

    Gary

  7. #7
    New Lounger
    Join Date
    Apr 2002
    Location
    Christchurch, New Zealand
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    Yes correct I am using docproperty. When I was first taught VBA I was told to use docproperty so thats my reason for using it. If you think bookmarks is easier then I will give it a go. I think one of the reason for using the docproperty rather than bookmarks was being able to set switches for controlling uppercase, lowercase etc within the document. Do you know how is can be done when using bookmarks?

    Rachael

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

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    Rachael,

    I haven't worked much with DocProperty fields so don't know their ins and outs. However I'd say that if you want to automatically insert a document property value into a document, then use a DocProperty field. And this will give you access to switches to control the case of the inserted content, as you say.

    However in this case it sounds like you want to insert an autotext entry into the document, so the DocProperty field isn't relevant. As far as controlling the case of the inserted content, in this instance it should not be an issue, since presumably you have already set up the autotext to contain the formatting which you want.

    There are no functions specific to bookmarks to control things like case, but there are a built-in VB/VBA functions that you can use, such as LCase and UCase, to manipulate the case of text strings.

    Gary

  9. #9
    New Lounger
    Join Date
    Apr 2002
    Location
    Christchurch, New Zealand
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Code for Inserting AutoTextEntries (Word97)

    Thanks for your help Gary. I will give the bookmarks a go for this instance. Unfortunately I can't get back into it today but will hopefully give it a go on Monday. Thanks again for your help.

Posting Permissions

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