Click here to Skip to main content
15,897,181 members

Comments by smehta.er (Top 2 by date)

smehta.er 25-Jun-14 14:29pm View    
Address is present at multiple places in the same doc. If I find and replace that with blank, there is a chance that address will be replaced at multiple places with blank. As of now, I found a workaround to delete the address. This address takes around 55 characters after the merge field. I am trying to delete 55 characters once I find the merge field in the doc and observe that the value retrieved from the database is Null or empty. Here is the sample code:

For Each wrdrange In wrdDoc.StoryRanges
With wrdrange.Find
.Forward = True
.ClearFormatting()
.Execute(FindText:=SAMPLEMERGEFIELD)
End With
If UCase(wrdrange.Text) = UCase(Trim(SAMPLEMERGEFIELD)) Then
If Trim(varsamplemergefield) = String.Empty Then
wrdrange.Delete(Unit:=Word.WdUnits.wdCharacter, Count:=55)
Else
wrdrange.Text = varsamplemergefield
End If
End If

Next wrdrange

I am looking for a solution to delete 3 lines rather than deleting 55 characters. I tried changing the units to wdLine but it does not work. Do you have any idea?
smehta.er 23-Jun-14 17:22pm View    
Thanks for the reply. The address is hardcoded in the doc. Are you saying that I would have to find this address in the word document and then delete it?