Replace Macro

P

Poli

Sorry forgot to tell you vital information, using Microsoft Word 2007,
running with XP.

I can't get this macro to work. I am trying to get it to work by entering
into two different fields based on what it reads in "PtNo6E100BB". Is this
possible. I know it works with one field but can't get it to work with two
different fields. Please help.

Sub Update6e100bb()
With ActiveDocument
If .FormFields("PtNo6E100BB").Result = "6E100BB191" Then
.FormFields("Descp6E100BB").Result = "Mount, 6E100 BACK TO BACK
W/1.91 SLEEVE"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB406" Then
.FormFields("Descp6E100BB").Result = "Mount, 6E100 BACK TO BACK
W/4.06 SLEEVE"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB475" Then
.FormFields("Descp6E100BB").Result = "Mount, 6E100 BACK TO BACK
W/4.75 SLEEVE"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB191" Then
.FormFields("PPK").Result = "6 or with nut 7"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB406" Then
.FormFields("PPK").Result = "5 or with nut 6"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB475" Then
.FormFields("PPK").Result = "5 or with nut 6"
End If
End With
End Sub

Was this post helpful to you?
 
D

Doug Robbins - Word MVP

Do it this way:

Sub Update6e100bb()
With ActiveDocument
If .FormFields("PtNo6E100BB").Result = "6E100BB191" Then
.FormFields("Descp6E100BB").Result = "Mount, 6E100 BACK TO BACK
W/1.91 SLEEVE"
.FormFields("PPK").Result = "6 or with nut 7"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB406" Then
.FormFields("Descp6E100BB").Result = "Mount, 6E100 BACK TO BACK
W/4.06 SLEEVE"
.FormFields("PPK").Result = "5 or with nut 6"
ElseIf .FormFields("PtNo6E100BB").Result = "6E100BB475" Then
.FormFields("Descp6E100BB").Result = "Mount, 6E100 BACK TO BACK
W/4.75 SLEEVE"
.FormFields("PPK").Result = "5 or with nut 6"
End If
End With
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

Graham Mayor

Although Doug's method works fine it might be easier to follow if you used
case statements eg

Sub Update6e100bb()
With ActiveDocument
Select Case .FormFields("PtNo6E100BB").Result

Case Is = "6E100BB191"
.FormFields("Descp6E100BB").Result = _
"Mount, 6E100 BACK TO BACK W/1.91 SLEEVE"
.FormFields("PPK").Result = "6 or with nut 7"

Case Is = "6E100BB406"
.FormFields("Descp6E100BB").Result = _
"Mount, 6E100 BACK TO BACK W/4.06 SLEEVE"
.FormFields("PPK").Result = "5 or with nut 6"

Case Is = "6E100BB475"
.FormFields("Descp6E100BB").Result = _
"Mount, 6E100 BACK TO BACK W/4.75 SLEEVE"
.FormFields("PPK").Result = "5 or with nut 6"

End Select
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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