Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Addin accessing Doc modules and the other way too (2000/Sr1)

    I have a word dot and a word addin with both having VBA code. I want to be able to get the value of a variable in either, such as from the dot I want to be able to get the value of a variable in the Addin or the Addin get a value from a variable in the dot. I also wish to access a function or sub in either from the other. How?

  2. #2
    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: Addin accessing Doc modules and the other way too (2000/Sr1)

    <P ID="edit" class=small>(Edited by jscher2000 on 24-Jun-03 17:15. Added the second point.)</P>When you say "variable," do you mean a document variable or a VBA variable? Each would present its own challenges.....

    Regarding procedures in other projects, see: Re: Calling procedure in another template (XP)

  3. #3
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Addin accessing Doc modules and the other way too (2000/Sr1)

    I think I would be accessing VBA variables and would be able to get access to Doucument variable indirectly that way such as a document name. For example in the Addin I would access the application's fullname by first placing it in a VBA variable named "fullname":
    fullname = Application.FullName

    And then access it from the template code and vice versa.

  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: Addin accessing Doc modules and the other way too (2000/Sr1)

    I should have been more specific. Word allows you to store variables in a document; these are known as document variables or docvars. These are distinct from properties of that document such as its name.

    Can you explain in more detail what you're trying to do? Generally speaking, VBA variables cease to exist once the code has run to completion. There are some exceptions because VB is not completely consistent about how it cleans up after itself, but it would not be 100% reliable to trust that the fullname variable in your example retains its value when accessed later by a different procedure.

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Addin accessing Doc modules and the other way too (2000/Sr1)

    if you create a public vba variable in an addin, you can access it from another document if that document (or template) contains a reference to the addin. the addin public vba variable will retain its value during the entire word session. however, there are some known bugs that reset public variables. if you work with userforms and error handling code (or the lack thereof)) you might run into trouble.

    the other way round you can have access from your addin to other document's variables the same way. in this case you need to late bind to the document and all variables need to be in the thisdocument class module.

    e.g.
    Dim x As Object
    'late bind to document 2
    Set x = Documents(2)
    'access variable (or property, or method) called testje
    'in the thisdocument class module
    MsgBox x.testje

    but i concur with Jefferson, explain us what you are trying to do and we might find a better way.

Posting Permissions

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