WordVB




Dim objWord As Word.Application
Dim strDocumentSave As String
Dim strSearch(14) As String
Dim strReplace(14) As String
Dim strDocumentName As String
Dim strInsertLine As String
Dim intCounter As Integer
Dim strContactName As String
Dim strSelectedName As String
Dim strFaxNumber As String
Dim intContactNumber As Integer
' instantate the objects

Set objWord = New Word.Application
strDocumentName = "GenStarQuotePOMaster.doc"
' add values to the search array

strSearch(0) = "<<ProducerName>>"
strSearch(1) = "<<ProducerFax>>"
strSearch(2) = "<<InsuredName>>"
strSearch(3) = "<<InsuredState>>"
strSearch(4) = "<<LobDescription>>"
strSearch(5) = "<<limit/occur>>"
strSearch(6) = "<<anag>>"
strSearch(7) = "<<Deductible>>"
strSearch(8) = "<<ConditionalField1>>"
strSearch(9) = "<<ConditionalField2>>"
strSearch(10) = "<<ConditionalField3>>"
strSearch(11) = "<<ConditionalField4>>"
strSearch(12) = "<<CommRate>>"
strSearch(13) = "<<Cname>>"
strSearch(14) = "<<Uname>>"
' now determine the values for the conditional fields

Select Case mvarProviderInfo.ProviderName
Case "General Star Indemnity"
strReplace(8) = "*Annual Premium:" & vbTab & vbTab & vbTab & CStr(Format(mvarPremium, "currency")) & _
vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "$0"
strReplace(9) = "*Loss Control Fee:" & vbTab & vbTab & vbTab & "$0.00" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "N/A"
strReplace(10) = "*The above may be subject to state surplus lines taxes and/or fees. Your " _
& "agency is responsible For calculating and remitting the taxes to the state."
strReplace(11) = "Public Officials coverages are being offered by " & mvarProviderInfo.ProviderName
If UCase(mvarTaxState) = "CT" Then
strReplace(11) = "Public Officials coverages are being offered by " & mvarProviderInfo.ProviderName
End If
Case Else
strReplace(8) = "Annual Premium:" & vbTab & vbTab & vbTab & CStr(Format(mvarPremium, "currency")) & _
vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "$0"
strReplace(9) = "Loss Control Fee:" & vbTab & vbTab & vbTab & "$0.00" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "N/A"
strReplace(10) = "The above may be subject to state surplus lines taxes and/or fees. Your " _
& "agency is responsible For calculating and remitting the taxes to the state."
strReplace(11) = "Public Officials coverages are being offered by GENERAL STAR NATIONAL (AN A++ Admitted Carrier)" & vbCr
If UCase(mvarTaxState) = "NY" Then
strReplace(11) = strReplace(11) & "COVERAGE IS OFFERED THROUGH THE NY FEE TRADE ZONE" & vbCr
End If
End Select
bring up the form to allow the user to select the producer contact info
Load frmContactSelect
frmContactSelect.Visible = False
DoEvents
'loop through the Producer contacts and add the names to the listbox on the form

For intCounter = 1 To mvarProducerInfo.Contacts.Count
With mvarProducerInfo.Contacts(intCounter)
strContactName = .FirstName & Space$(1) & .LastName
frmContactSelect.lstNames.AddItem strContactName
strContactName = ""
End With
Next
show the form modally to allow the user to select the contact
frmContactSelect.Show vbModal
strSelectedName = frmContactSelect.lstNames.List(frmContactSelect.lstNames.ListIndex)
intContactNumber = frmContactSelect.lstNames.ListIndex + 1
Unload frmContactSelect
Set frmContactSelect = Nothing
' add values to the replace array

strFaxNumber = mvarProducerInfo.Contacts(intContactNumber).FaxNumber
strReplace(0) = mvarProducerInfo.ProducerName
strReplace(1) = "(" & Left$(strFaxNumber, 3) & ")" & Space$(1) & Mid$(strFaxNumber, 4, 3) & "-" & Mid$(strFaxNumber, 7)
strReplace(2) = mvarInsuredName
strReplace(3) = mvarInsuredState
strReplace(4) = mvarSLOBDescription
strReplace(5) = CStr(Format(mvarLimitPerOccurance, "currency")) & Space$(1)
strReplace(6) = CStr(Format(mvarLimitAnnualAgg, "currency")) & Space$(1)
strReplace(7) = CStr(Format(mvarDeductible, "currency")) & Space$(1)
strReplace(12) = "0" ' For now
strReplace(13) = strSelectedName
strReplace(14) = mvarUnderwriterName
' assign a value for the saved document name

strDocumentSave = App.Path & "\letters\pipssavedletters\" _
& StrConv(mvarProducerInfo.ProducerName, vbProperCase) & " GenStarPOQuote " & _
Format(Date, "mddyy") & ".doc"
'see if save name document exists, if so delete it

If Dir(strDocumentSave) <> "" Then Kill strDocumentSave
'check to see if the master document for this letter exists

If Dir(App.Path & "\letters\" & strDocumentName) = "" Then
RaiseEvent MasterDocumentNotFound("Unable to find " & strDocumentName & " file.")
objWord.Quit SaveChanges:=wdDoNotSaveChanges
Set objWord = Nothing
End If
'add this information to the GenStarQuote master document

objWord.Documents.Open App.Path & "\letters\" & strDocumentName
objWord.ActiveWindow.WindowState = wdWindowStateNormal
For intCounter = 0 To 12
With objWord.ActiveDocument.Content.Find
.Text = strSearch(intCounter)
.Replacement.Text = strReplace(intCounter)
.Forward = True
.Execute Replace:=wdReplaceAll
End With
Next
'insert the rest of the text needed if the provider it genstar indemnity

If mvarProviderInfo.ProviderName = "General Star Indemnity" Then
Select Case UCase(mvarTaxState)
Case "NY"
strInsertLine = " (An A++ Rated Surplus Lines Carrier). YOUR " & _
"AGENCY IS RESPONSIBLE For MAKING SURPLUS LINES FILINGS With THE STATE. PLEASE PROVIDE A COPY OF " & _
" YOUR SURPLUS LINES LICENSE If NOT PREVIOUSLY PROVIDED."
Case "CT"
strInsertLine = "(An A++ Rated Admitted Carrier in Connecticut). YOUR AGENCY IS RESPONSIBLE For MAKEING SURPLUS LINES " _
& " FILINGS With THE STATE. PLEASE PROVIDE A COPY OF YOUR SURPLUS LINES LICENSE If NOT PREVIOUSLY PROVIDED."
End Select
objWord.Selection.Find.Text = mvarProviderInfo.ProviderName
objWord.Selection.Find.Execute
objWord.Selection.InsertAfter strInsertLine
objWord.Selection.Font.Bold = False
End If
' bold the provider name in the document

With objWord.ActiveDocument.Content.Find
.Text = UCase(mvarProviderInfo.ProviderName)
.Replacement.Text = mvarProviderInfo.ProviderName
.Replacement.Font.Bold = True
.Forward = True
.Execute Replace:=wdReplaceAll
End With
' if the tax state equals new york, then we must remove part of one phrase

If UCase(mvarTaxState) = "NY" Then
With objWord.ActiveDocument.Content.Find
.Text = "non-monetary"
.Replacement.Text = Space$(1)
.Replacement.Font.Bold = True
.Forward = True
.Execute Replace:=wdReplaceAll
End With
End If
objWord.Selection.Collapse wdCollapseEnd
' save the document with a new name

objWord.Documents(strDocumentName).SaveAs strDocumentSave, , , , True
' make the document visible

objWord.Application.Visible = True
Inputs:
the code is looking for a document that was pre-setup as a
template. the fields that look like "<<xxxxxx>>" are place
holders in the template. The replacement values were
generated by stored procedures run against a sql server
database. If there is interest I will post the ado routines
that I used to get the data.

Assumes:
make sure that you set a reference to the word object using
the Project/References menu. Almost all variables (except
those explicitly stated as local) are module level variables
private to the class module. all the vbTab constants appended
to the strings are used simple to align the text. If anyone
knows of a better way to do this, I would love to hear it.
this subroutine/method is used to print the Genstar Public
Officals quote letter. The method expects no values to be
passed and the method has no return values.












( wordvb.html )- by Paolo Puglisi - Modifica del 17/12/2023