Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Variables shorthand (Word VBA)

    Hi folks, just a silly probably very quick little question, please ...!

    The templates I'm currently working on require repeated and frequent use of the line:

    activedocument.variables("blah").value

    and I'd really like to use either a function or just a dim/set combo to create something like

    adv("blah")

    to speed things up a bit - but when I try something goes wrong and it won't compile! The function I tried was:

    function adv (var as string)
    application.activedocument.variables(var).value
    end function

    and I tried a dim/set combo too, different error messages but stil won't work:

    dim adv as [variable?]
    set adv as [activedocument.variables?]

    I'm sure it's just something stupid (I'm still a bit rusty after a couple of years out!) but I cannot for the life of me think what it is!

    Help?! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    Many thanks
    Beryl M


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

    Re: Variables shorthand (Word VBA)

    In a function, you must assign a value to the function name:

    Function adv(var As String) As String
    adv = ActiveDocument.Variables(var)
    End Function

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Variables shorthand (Word VBA)

    Hi Hans, long time no 'speak'!

    Many thanks for this, I knew it would be something stupid (on my part, that is, of course)!!
    Beryl M


  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Variables shorthand (Word VBA)

    Hi Beryl,
    You can also use:
    <pre> Dim adv As Variables
    Set adv = ActiveDocument.Variables
    MsgBox adv("test")
    </pre>

    FWIW.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Variables shorthand (Word VBA)

    Thanks, Rory - that was the other method I tried (and failed) to use - thanks for straightening me out!
    Beryl M


Posting Permissions

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