michielh
04-21-2006, 01:38 PM
Hi there,
I am pretty experienced in using VBA with Access but using Word VBA is still very new to me.
I have a userform that shows some doc-properties in textboxes and gives the user a chance to change them. I use the on activate event of the document to open the form and the on click event of an ok button to close it again. Works fine until ....
Until someone asked me to change the forms functionality. When the form opens, not all doc-properties should be shown. Every doc-property having a string-value starting with < and ending with > should not be shown. I tried the following code but the "for each object in collection" part does not work. What am I doing wrong here?
Private Sub UserForm_Activate()
TextBox1.Value = ActiveDocument.CustomDocumentProperties("<companyname>").Value
TextBox2.Value = ActiveDocument.CustomDocumentProperties("<address>").Value
TextBox7.Value = ActiveDocument.CustomDocumentProperties("<attention>").Value
'and lots more but not shown here...
TextBox4.Value = ActiveDocument.BuiltInDocumentProperties("Title").Value
TextBox5.Value = ActiveDocument.BuiltInDocumentProperties("Subject").Value
TextBox6.Value = ActiveDocument.BuiltInDocumentProperties("Author").Value
'and lots more as well...
Dim xxx As FormField
For Each xxx In ActiveDocument.FormFields
With ActiveDocument.FormFields(xxx)
If .Type = wdFieldFormTextInput Then
If Left(.Result, 1) = "<" And Right(.Result, 1) = ">" Then
.Result = " "
End If
End If
End With
Next xxx
End Sub
I am pretty experienced in using VBA with Access but using Word VBA is still very new to me.
I have a userform that shows some doc-properties in textboxes and gives the user a chance to change them. I use the on activate event of the document to open the form and the on click event of an ok button to close it again. Works fine until ....
Until someone asked me to change the forms functionality. When the form opens, not all doc-properties should be shown. Every doc-property having a string-value starting with < and ending with > should not be shown. I tried the following code but the "for each object in collection" part does not work. What am I doing wrong here?
Private Sub UserForm_Activate()
TextBox1.Value = ActiveDocument.CustomDocumentProperties("<companyname>").Value
TextBox2.Value = ActiveDocument.CustomDocumentProperties("<address>").Value
TextBox7.Value = ActiveDocument.CustomDocumentProperties("<attention>").Value
'and lots more but not shown here...
TextBox4.Value = ActiveDocument.BuiltInDocumentProperties("Title").Value
TextBox5.Value = ActiveDocument.BuiltInDocumentProperties("Subject").Value
TextBox6.Value = ActiveDocument.BuiltInDocumentProperties("Author").Value
'and lots more as well...
Dim xxx As FormField
For Each xxx In ActiveDocument.FormFields
With ActiveDocument.FormFields(xxx)
If .Type = wdFieldFormTextInput Then
If Left(.Result, 1) = "<" And Right(.Result, 1) = ">" Then
.Result = " "
End If
End If
End With
Next xxx
End Sub