Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Getting a wdproperty name into a variable (VBA/Wor

    Dear Loungers,

    I want to do this:

    ActiveDocument.BuiltInDocumentProperties(wdPropert ytitle).Value = "user input text"

    the values for the property name, in the example wdPropertyTitle, and the user input text are held as part of a) the control tag property and [img]/forums/images/smilies/cool.gif[/img] the data entered by the user in the control. So the specific code above becomes generalised to:

    strCurrentControl = objControl ' set to the user input i.e. what's on form
    bipCurrentControlTag = objControl.Tag ' the tag holds the value e.g. "wdPropertyTitle"
    ActiveDocument.BuiltInDocumentProperties(bipCurren tControlTag).Value = strCurrentControl

    where bipCurrentControlTag is defined as a WdBuiltInProperty and strCurrentControl as String

    no matter what I haven't been able to get the WdBuiltInProperty name into the bipCurrentControlTag, I get a type mismatch error, but I know that this works:

    strCurrentControl = "user input text" ' set to the user input i.e. what's on form"
    bipCurrentControlTag = wdPropertyTitle ' set to the tag value - to identify "builtin"
    ActiveDocument.BuiltInDocumentProperties(bipCurren tControlTag).Value = strCurrentControl

    Therefore I think the error is because the property name is held as a string in the tag property how do I get the string "wdPropertyTitle" into the variable?

    thank you liz

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

    Re: Getting a wdproperty name into a variable (VBA/Wor

    The wdProperty... constants are numbers (Integers), not strings.

    One possibility is to look up the value of the constant in the Object Browser (press F2 to activate it) and use that. For example, wdPropertyTitle = 1, so if you set the Tag of the control to 1 instead of wdPropertyTitle, you should be able to use your code.

    Another option is to use a Select Case Statement:

    Select Case objControl.Tag
    Case "wdPropertyTitle
    bipCurrentControlTag = wdPropertyTitle
    Case "wdPropertyAuthor"
    bipCurrentControlTag = wdPropertyAuthor
    ...
    End Select

  3. #3
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Getting a wdproperty name into a variable (VBA

    Hans,

    once again, thank you! I shall use the number idea since I don't want to amend code if we decide to add more, and we are using a number of them. So the numbers in the tag idea is more elegant and maintainable.

    This thing wouldn't have got written without your help!

    liz

Posting Permissions

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