Visio Guy

Visio Discussions => Programming & Code => Topic started by: Hamwic on November 03, 2015, 10:41:58 AM

Title: Creating a ComboBox from Shape Data Fields
Post by: Hamwic on November 03, 2015, 10:41:58 AM
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!
Title: Re: Creating a ComboBox from Shape Data Fields
Post by: Surrogate on November 03, 2015, 11:25:08 AM
sometimes ago i create userform with comboboxes which data contain in TheDoc!user cells
you can download this file there (http://visio.getbb.ru/download/file.php?id=304)

Look in UserForm_Initialize routine there you find load combobox list
Title: Re: Creating a ComboBox from Shape Data Fields
Post by: Hamwic on November 03, 2015, 11:44:47 AM
Thanks Surrogate, but your file didn't open correctly. I couldn't see the code.
Title: Re: Creating a ComboBox from Shape Data Fields
Post by: Surrogate on November 03, 2015, 11:53:50 AM
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
Title: Re: Creating a ComboBox from Shape Data Fields
Post by: Hamwic on November 04, 2015, 01:19:32 PM
I haven't had a chance to look at this yet, but will give feedback when I can.

Thanks!
Title: Re: Creating a ComboBox from Shape Data Fields
Post by: Hamwic on November 10, 2015, 02:17:56 PM
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!
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 55 (show)
Files included: 25 - 925KB. (show)
Memory used: 773KB.
Tokens: post-login.
Cache hits: 6: 0.00100s for 22,291 bytes (show)
Cache misses: 1: (show)
Queries used: 8.

[Show Queries]