Creating a ComboBox from Shape Data Fields

Started by Hamwic, November 03, 2015, 10:41:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hamwic

Hi...

I'm trying to use VBA to create a ComboBox in Visio, populated by the fields (Rows?) in the shape data.

The reasoning: There is an organisation chart which contains the names and positions of employees. I have created code that inserts a new field, but left it blank so that the user can enter data at a later date. Now, I want to create a UserForm that contains a ComboBox of all the fields (Rows?) in each shape (person). This way, the user can choose which field to update. After selection, this will start another macro which then prompts the user to enter a value against each shape sequentially - this part has already been written and will only need minor tweaking later. All fields (rows?) are the same for each shape.

Please explain in laymean's terms as I am new to Visio and not an expert VBA user (I would consider myself beginner/intermediate!)

Thanks in advance!

Surrogate

sometimes ago i create userform with comboboxes which data contain in TheDoc!user cells
you can download this file there

Look in UserForm_Initialize routine there you find load combobox list

Hamwic

Thanks Surrogate, but your file didn't open correctly. I couldn't see the code.

Surrogate

huh ?
Private Sub UserForm_Initialize()
fst = True
Me.txtTitul.Text = Replace(ActiveDocument.DocumentSheet.Cells("user.titul").FormulaU, Chr(34), "")
Me.txtObject.Text = Replace(ActiveDocument.DocumentSheet.Cells("user.Object").FormulaU, Chr(34), "")
Me.txtDec.Text = Replace(ActiveDocument.DocumentSheet.Cells("user.dec").FormulaU, Chr(34), "")
Me.txtManufact.Text = Replace(ActiveDocument.DocumentSheet.Cells("user.Manufact").FormulaU, Chr(34), "")
Me.txtBook.Text = Replace(ActiveDocument.DocumentSheet.Cells("user.Book").FormulaU, Chr(34), "")
Me.DTP1.Value = Replace(ActiveDocument.DocumentSheet.Cells("user.date").FormulaU, Chr(34), "")
cmbAuthor.List = Split(Replace(ActiveDocument.DocumentSheet.Cells("prop.author.format").FormulaU, Chr(34), ""), ";")
cmbAuthor.Text = Replace(ActiveDocument.DocumentSheet.Cells("prop.author").FormulaU, Chr(34), "")
cmbControl.List = Split(Replace(ActiveDocument.DocumentSheet.Cells("prop.control.format").FormulaU, Chr(34), ""), ";")
cmbControl.Text = Replace(ActiveDocument.DocumentSheet.Cells("prop.control").FormulaU, Chr(34), "")
cmbGIP.List = Split(Replace(ActiveDocument.DocumentSheet.Cells("prop.gip.format").FormulaU, Chr(34), ""), ";")
cmbGIP.Text = Replace(ActiveDocument.DocumentSheet.Cells("prop.gip").FormulaU, Chr(34), "")
cmbNCont.List = Split(Replace(ActiveDocument.DocumentSheet.Cells("prop.ncont.format").FormulaU, Chr(34), ""), ";")
cmbNCont.Text = Replace(ActiveDocument.DocumentSheet.Cells("prop.ncont").FormulaU, Chr(34), "")
cmbUtv.List = Split(Replace(ActiveDocument.DocumentSheet.Cells("prop.utv.format").FormulaU, Chr(34), ""), ";")
cmbUtv.Text = Replace(ActiveDocument.DocumentSheet.Cells("prop.utv").FormulaU, Chr(34), "")
fst = False
End Sub

Hamwic

I haven't had a chance to look at this yet, but will give feedback when I can.

Thanks!

Hamwic

Thanks for the code, but I did find an alternative way of getting the list.

Dim intCount As Integer
Dim intLoopCounter As Integer
Dim strFieldValue As String
Dim vsoPage As Visio.Page, vsoShape As Visio.Shape

intLoopCounter = 0
intCount = 0
Set vsoPage = ActiveDocument.Pages("Core")
Set vsoShape = vsoPage.Shapes.ItemFromID(12)
intCount = vsoShape.RowCount(Visio.visSectionProp)

Do Until intLoopCounter = intCount
    strFieldValue = vsoShape.Section(visSectionProp).Row(intLoopCounter).Name
    With ComboBox1
        .AddItem strFieldValue
    End With
   
    intLoopCounter = intLoopCounter + 1
Loop

This looks at a shape on a page, counts how many rows it has, then uses this as a counter to scroll through getting the row names and adding them to the ComboBox!!

p.s. I don't know how to enter code into here and show it like you have - so apologies for that!