![]() |
|
#1
|
||||
|
||||
![]() The approach I suggested has nothing to do with changing how anything appears.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
Any suggestions on how the code should look to pull the Heading styles?
Ideally, I would select the contract from a drop down combo box (Named cboContractForm) which corresponds to the bookmark that surrounds contract 1, contract 2, etc... click a button named cmdLoad, which then loops through the bookmarks contained / nested within the contract bookmark and loads the heading text from each bookmark to define the caption. It would be similar to the following, but I am struggling to figure out how to setup the code to achieve this. Code:
Private Sub UserForm_Initialize() With cboContractForm .AddItem "Contract 1" .AddItem "Contract 2" End With End Sub Based on the selected contract, update the check boxes for each term: Code:
Private Sub cmdLoad_Click() Dim Contract as String If cboContractForm = "Contract 1" Then Contract = “Contract1” ‘Name of Bookmark Range If cboContractForm = "Contract 2" Then Contract = “Contract2” ‘Name of Bookmark Range Dim bmk As Bookmark Dim i As Long Dim P As String Dim CovOutput As String Dim msg As String i = 1 For Each bmk In ActiveDocument.Bookmarks(Contract).Range.Bookmarks 'Bookmark for entire contract - Set based on cboContractForm combobox. CovOutput = bmk.Name P = i Controls("CheckBox" & P).Tag = bmk.Name 'Set Tag equal to the bookmark that corresponds with the term being loaded into the Userform. If the text box is false I will use the tag name to determine which bookmarks to clear from the form. Controls("CheckBox" & P).Caption = Word 's Heading Styles for your Term text? 'Heading Text from within the found / looped bookmark. Controls("CheckBox" & P).ControlTipText = bmk 'Mouse over to show the entire term msg = msg & bmk.Name & vbCr i = (i + 1) On Error GoTo ErrorStop Next bmk ErrorStop: 'Uncomment for Debug 'MsgBox msg End Sub After selecting the applicable text boxes, click OK to update the letter. Code:
Private Sub cmdOK_Click() On Error Resume Next With ActiveDocument If cboContractForm = "Contract 1" Then .Bookmarks("Contract1").Range.Text = "" If cboContractForm = "Contract 2" Then .Bookmarks("Contract2").Range.Text = "" Else 'Remove terms that do not apply If CheckBox1 = False Then .Bookmarks("CheckBox1.Tag.Value").Range.Text = "" If CheckBox2 = False Then .Bookmarks("CheckBox2.Tag.Value").Range.Text = "" If CheckBox3 = False Then .Bookmarks("CheckBox3.Tag.Value").Range.Text = "" If CheckBox4 = False Then .Bookmarks("CheckBox4.Tag.Value").Range.Text = "" 'etc for each check box End If End With End Sub I have never used header styles to pass values / extract text and I am not quite sure how to obtain values or reference ranges. The above codes do not work, but help to explain my thought process. Any updates would be greatly appreciated. Thank you, John |
![]() |
Tags |
bold, extract, string |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Formula to Extract text from a text string | Haha88 | Excel | 2 | 11-14-2017 01:32 AM |
![]() |
Haha88 | Excel | 8 | 02-13-2017 05:06 PM |
![]() |
kirkm | Word VBA | 7 | 09-11-2016 06:13 PM |
Extract numbers from a text string | aleale97 | Excel | 4 | 02-10-2011 10:33 AM |
Extract from String using Wildcard | whousedmy | Word | 0 | 05-21-2009 01:35 AM |