Hi all,
First post here – I’ve been lurking for a few weeks trying to work on a small project and the help here has been incredible, but I’m still having some problems!
I’ve got a userform that fills in the blanks in a document. Having used some of the excellent code examples on here and elsewhere, I originally tried to use bookmarks to insert the values – which does the job well, were it not for the fact that I need to insert the info from the bookmarks in more than one place. I can’t get the bookmark crossreferencing trick to work, so I decided to go down (as I’ve seen recommended elsewhere) the custom document property route.
I’ve hit a bit of a brick wall with the code though – I can’t see where I’m going wrong, but I keep getting an argument not optional error.
Option Explicit Private Sub cboSenderAddress_Change() End Sub Private Sub cmdCancel_Click() Unload Me ActiveDocument.Close SaveChanges:=False End Sub Private Sub cmdClear_Click() txtInsured.Value = Null txtCWDescription.Value = Null txtSalutation.Value = Null cboPII.Value = Null cboInsuredRole.Value = Null cboParty2Role.Value = Null txtParty2.Value = Null txtParty3.Value = Null cboParty3Role.Value = Null cboStepIn.Value = Null End Sub Private Sub cmdOK_Click() WriteCustomProp(“Insured”).Range.Text , txtInsured.Value, msoPropertyTypeString WriteCustomProp(“CWDescription”).Range.Text , txtCWDescription.Value, msoPropertyTypeString WriteCustomProp(“PII”).Range.Text , cboPII.Value, msoPropertyTypeString WriteCustomProp(“InsuredRole”).Range.Text , cboInsuredRole.Value, msoPropertyTypeString WriteCustomProp(“Party2Role”).Range.Text , cboParty2Role.Value, msoPropertyTypeString WriteCustomProp(“Party2”).Range.Text , txtParty2.Value, msoPropertyTypeString WriteCustomProp(“Party3”).Range.Text , txtParty3.Value, msoPropertyTypeString WriteCustomProp(“Party3Role”).Range.Text , cboParty3Role.Value, msoPropertyTypeString ActiveDocument.Fields.Update End With Application.ScreenUpdating = True Unload Me End Sub Function WriteCustomProp(sProp As String, sValue As String, iType As Integer) As Boolean Dim prop As DocumentProperty, bExists As Boolean bExists = False For Each prop In ActiveDocument.CustomDocumentProperties If LCase(prop.Name) = LCase(sProp) Then bExists = True prop.Value = sValue Exit For End If Next If Not bExists Then ActiveDocument.CustomDocumentProperties.Add Name:=sProp, Value:=sValue, _ LinkToContent:=False, Type:=iType End If End Function Private Sub Label1_Click() End Sub Private Sub Label10_Click() End Sub Private Sub Label14_Click() End Sub Private Sub optGreeting1_Click() End Sub Private Sub txtInsured_Change() End Sub Private Sub UserForm_Initialize() With cboInsuredRole .AddItem “Contractor” .AddItem “Subcontractor” .AddItem “Trade Contractor” End With With cboParty2Role .AddItem “Contractor” .AddItem “Funder” .AddItem “Employer” .AddItem “Local Authority” End With With cboParty3Role .AddItem “Contractor” .AddItem “Funder” .AddItem “Employer” .AddItem “Local Authority” End With End Sub
If anyone can help me I would be very, very grateful – if you can explain it to me as if I’m a five year old, that would be even more helpful!
Credit to Andrew Lockton for snippets of the code above, great to learn from.
Thanks!
PS it’s still a WIP so some of the references to labels etc haven’t been filled in yet.