none
Word Text box copy data and edit RRS feed

  • Question

  • Hi guys,

    I am sure this is not too hard to do but I cannot find the right information to get started. I have not worked in VBS, VBA in some time. Also would like this to work in Word 2013. 

    What i want to do is create a new user form template. That is someone add name, surname and this will create the default user name in both formats (2000 and 2003+) and also email address

    EG  User enters, Name field, Surname Field. 

    on exit

    Logon name = domain\name surname (20chr limit)

    FQDN name surname@domain.com

    email = name.surname@domain.com

    I though this would be simple as creating a VBA script that activates on exit, loss of focus for TextboxName and then fills in the other text box. Yet I cannot correctly find how to Label the textbox (TAG field I think) then access the on exit or loss of focus field script.

    I think its something like.

    Activedocument.shape(textname) on exit

    activedocument.share(TextEmail).result = activedocument.shape(textName).result 

    Can someone tell me how to do this or link a page. I will have to do some extra coding where logon name equals name + surname first 20 characters but I should be able to do that ok.

    Thanks for your time.

    Craig


    Craig

    Monday, September 7, 2015 3:27 AM

Answers

  • Hi guys,

    I have the answer as expect not to hard once you know the code.

    You create a text control box

    Give it a tag

    Open VBA and create the following.

    Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    ' dostuff
    If CC.Tag = "txtSurname" Then dostuff
     If CC.Tag = "txtName" Then dostuff

    End Sub

    Then create a function or sub called in this case dostuff.

    Craig


    Craig

    • Marked as answer by Craig Garland Tuesday, September 8, 2015 6:05 AM
    Tuesday, September 8, 2015 6:04 AM

All replies

  • Hi Craig,

    This is the forum to discuss questions and feedback for Microsoft word, I'll move your question to the MSDN forum for Word

    https://social.msdn.microsoft.com/Forums/en-US/home?category=officedev&filter=alllanguages

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Emi Zhang
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs. Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, September 8, 2015 6:00 AM
  • Hi guys,

    I have the answer as expect not to hard once you know the code.

    You create a text control box

    Give it a tag

    Open VBA and create the following.

    Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    ' dostuff
    If CC.Tag = "txtSurname" Then dostuff
     If CC.Tag = "txtName" Then dostuff

    End Sub

    Then create a function or sub called in this case dostuff.

    Craig


    Craig

    • Marked as answer by Craig Garland Tuesday, September 8, 2015 6:05 AM
    Tuesday, September 8, 2015 6:04 AM