View Single Post
 
Old 04-07-2016, 11:33 AM
highrise955 highrise955 is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Code:
Option Explicit
Private Sub CANCELbutton_Click()
Me.Hide
Me.Tag = 0
End Sub

Private Sub OKbutton_Click()
Me.Hide
Me.Tag = 1
End Sub
is what goes in the userform code module. This hides the userform and passes the control to the calling macro Sub Main() which continues based on the value of Me.Tag.

The parts that you added to the above go in the code that calls the userform e.g. as follows. The Excel function also goes in the same module as Sub Main.

Code:
Sub Main()
Dim oFrm As New DrawingNumberEntryForm
    With oFrm
        xlFillList ListOrComboBox:=.DrawingNumberUf, _
                   iColumn:=1, _
                   strWorkbook:="C:\Temp\ItemSheet.xlsx", _
                   strRange:="CollRange", _
                   RangeIsWorksheet:=False, _
                   RangeIncludesHeaderRow:=True
        .Show
        If .Tag = 0 Then GoTo lbl_Exit 'Cancel was selected
        ActiveDocument.SelectContentControlsByTitle("Drawing Number").Item(1).Range.Text = .DrawingNumberUf.Text
    End With
lbl_Exit:
    Unload oFrm
    Set oFrm = Nothing
    Exit Sub
End Sub
Graham,

It's working great! Thanks a lot.

I have one final issue I was hoping I could figure out on my own but I'm not having any luck. Maybe you can offer a suggestion or two?

Below is the sample table I am using in Excel. Currently the range include all three columns.



Populating the "Drawing Number" using this code...

Code:
ActiveDocument.SelectContentControlsByTitle("Drawing Number").Item(1).Range.Text = .DrawingNumberUf.Text
in the Sub Main() module works perfectly. However, I am trying to figure out how to populate other content controls with the "Rev" and "Name" values. I will be adding a few other columns shortly and will need to do the same for them.

Any suggestions or links to your web site where you cover this would be greatly appreciated.

As always, thanks for your help.
Reply With Quote