reducing font of a bookmark field

C

Charlie

I'd like to add some code that would check to see if the text of a bookmark
field is two lines (containing a paragraph mark) and if it is, then to reduce
the font of all those bookmarks to 10 point so it will fit in the allotted
space in my form. Thanks, charlie
 
G

Greg

Charlie,

Something like:

Sub ScratchMacro()
Dim oBkm As Bookmark

For Each oBkm In ActiveDocument.Bookmarks
If InStr(oBkm.Range.Text, vbCr) Then
oBkm.Range.Font.Size = 10
End If
Next oBkm
End Sub
 
G

Greg

Charlie,

Something like:

Sub ScratchMacro()
Dim oBkm As Bookmark

For Each oBkm In ActiveDocument.Bookmarks
If InStr(oBkm.Range.Text, vbCr) Then
oBkm.Range.Font.Size = 10
End If
Next oBkm
End Sub
 
C

Charlie

Hi again, I tried this but it didn't do anything. I have about 4 different
bookmarks in my form. I have an AutoNew macro running which updates all
fields when I open it. The first fields are 4 (ASK) fields which gets the
data from the user and defines the bookmarks. then the Bookmarks are used
multiple times in the form. The bookmark that may contain 2 lines (a return
key) is called {Location}. I put the code you stated at the end of my
AutoNew() but it didn't change the font of any fields. Is there something
else wrong? I'm not sure how the field propertys works as far as preserving
style on update. Should that be checked? I tried it both ways but it didn't
seem to make a difference. BTW, I'm using Office XP if that helps. Thanks,
charlie
 
C

Charlie

PS. I copied the code out of your scratchmacro and inserted it right at the
end of my AutoNew() macro.
 
G

Greg Maxey

Charlie,

Then you don't have bookmarked text in your document, you have REF Fields.
If you proviided the input via a ASK input screen then what you call
paragraph marks are line breaks. Try:

Sub ScratchMacro()
Dim oFld As Field

For Each oFld In ActiveDocument.Fields
If InStr(oFld.Result.Text, Chr(11)) > 0 Then
oFld.Result.Font.Size = 10
End If
Next oFld
End Sub
 
C

Charlie

GREAT!!! This worked. However, I need to update only a specific field with
the name {LOCATION}, but this changed other fields, too. How do I change
this code to do only the field {location}? many thanks, charlie
 
G

Greg Maxey

Charlie,

What have your tried?

Try:

Sub ScratchMacro()
Dim oFld As Field

For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldRef Then
If InStr(oFld.Code.Text, "Location") Then
If InStr(oFld.Result.Text, Chr(11)) > 0 Then
oFld.Result.Font.Size = 10
End If
End If
End If
Next oFld
End Sub
 
G

Greg Maxey

or

Sub ScratchMacro()
Dim oFld As Field

For Each oFld In ActiveDocument.Fields
If InStr(oFld.Code.Text, "Location") _
And InStr(oFld.Result.Text, Chr(11)) > 0 Then
oFld.Result.Font.Size = 10
End If
Next oFld
End Sub
 
C

Charlie

Many Many thanks, Greg
ps. is there some kind of help file download that would help me with basic
word programming that would have lots of examples? The built in help file
seems limited... Thanks, Chalrie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top