View Single Post
 
Old 10-08-2015, 08:27 AM
DocTeam10 DocTeam10 is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Oct 2015
Location: Massachusetts, USA
Posts: 1
DocTeam10 is on a distinguished road
Default UserForm to Add XML Mapped Content Controls

Hey Everybody - I'm hoping that someone here can tell me what I'm doing wrong. I'm a complete newb with XML, and I'm having a hard time with a UserForm.

Thanks in advance for taking a look!!!

I'm working on a UserForm that does a few things
  • Adds a content control, either plain text or drop-down list based on selection
  • Updates the content control Title and Tag properties
  • Sets the placeholder text
  • Sets the XML Mapping

I have a macro that does this for specific things, Client and Vendor. So that info, and the XML paths are in the code. But I want to take input from the User form to create the XML path. I can get everything but that last bullet to work.

This is the code I have so far:

Code:
Option Explicit
    Dim strField As String
    Dim strPlace As String
    Dim strXML As String
    Dim strType As String

Private Sub UserForm_Initialize()
    txtPlace.Value = "<< >>"
    txtXML.Value = "/root/"
    
    With cmbType
        .AddItem "Plain Text"
        .AddItem "Drop-Down"
    End With
End Sub

Private Sub cmdOK_Click()
    XMLField.Hide
   


'define strType
    If cmbType.Value = "Plain Text" _
        Then strType = "Plain"
    If cmbType.Value = "Drop-Down" _
        Then strType = "List"
'define other strings
    strField = txtField.Value
    strPlace = txtPlace.Value
    strXML = txtXML.Value

'add content control

With Selection.Range
    If strType = "Plain" _
        Then .ContentControls.Add (wdContentControlText)
    If strType = "List" _
        Then .ContentControls.Add (wdContentControlDropdownList)

End With
    Selection.ParentContentControl.Title = strField
    Selection.ParentContentControl.Tag = strField
    Selection.ParentContentControl.XMLMapping.SetMapping xPath:=strXML
    Selection.ParentContentControl.SetPlaceholderText Text:=strPlace

End Sub
Reply With Quote