VeryTerry
02-14-2014, 11:33 AM
I am stuck with trying to get specific text to print out depending on a user’s choice on a User Form. I’m not a skilled vba-er; I’ve been trying to adapt existing code to my purpose, and have tried many different approaches. I am using Word 2010, VBA 7.0.
Here’s the scenario: I am adding “letterhead” graphics and text to the top of a letter. The address vba code works fine. But I want to add text to the bottom based on what choice the user makes in a form:
frmSimulateHCSLetterhead.Show
Here’s the code in the form:
Private Sub CmdOK_Click()
Dim p_sContractorLic As String
Select Case Me.OptAZ.Value
Case True: p_sContractorLic = "AZ"
Unload Me
Case False:
End Select
Select Case Me.OptFL.Value
Case True: p_sContractorLic = "FL"
Unload Me
Case False:
End Select
Select Case Me.OptCA.Value
Case True: p_sContractorLic = "CA"
Unload Me
Case False:
End Select
Select Case Me.OptNone.Value
Case True: p_sContractorLic = ""
Unload Me
Case False:
End Select
End Sub
And here is the related code in the document. I want to find the text “CLN”, delete it (find a bookmark) and insert the number associated with the user’s choice in the form:
Dim strContractorLic As String
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Collapse Direction:=wdCollapseStart
Set rTemp = Selection.Range
rTemp.Find.Execute findtext:="CLN", Forward:=True
rTemp.Select
If p_sContractorLic = "AZ" Then
strContractorLic = "280646"
End If
If p_sContractorLic = "CA" Then
strContractor = "848414"
End If
If p_sContractorLic = "FL" Then
strContractor = "CGC1520478"
End If
If p_sContractorLic = "" Then
strContractor = ""
End If
With Selection
.Delete
.InsertAfter Text:=p_sContractorLic
.Collapse Direction:=wdCollapseEnd
End With
I also tried using Select Case
Can anyone help?
Here’s the scenario: I am adding “letterhead” graphics and text to the top of a letter. The address vba code works fine. But I want to add text to the bottom based on what choice the user makes in a form:
frmSimulateHCSLetterhead.Show
Here’s the code in the form:
Private Sub CmdOK_Click()
Dim p_sContractorLic As String
Select Case Me.OptAZ.Value
Case True: p_sContractorLic = "AZ"
Unload Me
Case False:
End Select
Select Case Me.OptFL.Value
Case True: p_sContractorLic = "FL"
Unload Me
Case False:
End Select
Select Case Me.OptCA.Value
Case True: p_sContractorLic = "CA"
Unload Me
Case False:
End Select
Select Case Me.OptNone.Value
Case True: p_sContractorLic = ""
Unload Me
Case False:
End Select
End Sub
And here is the related code in the document. I want to find the text “CLN”, delete it (find a bookmark) and insert the number associated with the user’s choice in the form:
Dim strContractorLic As String
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Collapse Direction:=wdCollapseStart
Set rTemp = Selection.Range
rTemp.Find.Execute findtext:="CLN", Forward:=True
rTemp.Select
If p_sContractorLic = "AZ" Then
strContractorLic = "280646"
End If
If p_sContractorLic = "CA" Then
strContractor = "848414"
End If
If p_sContractorLic = "FL" Then
strContractor = "CGC1520478"
End If
If p_sContractorLic = "" Then
strContractor = ""
End If
With Selection
.Delete
.InsertAfter Text:=p_sContractorLic
.Collapse Direction:=wdCollapseEnd
End With
I also tried using Select Case
Can anyone help?