VB editor doesn't take Spanish

J

John Smith

My VB editor doesn't take Spanish. When I paste Spanish to the
editor, those letters with an accent becomes two letters, e.g. ó
becomes o', ñ becomes n~, etc. I used the language tool to add
Spanish to Word. That did not help. I'm trying to do a find and
replace to replace English text with Spanish. This won't work if
the replacement text can't be in Spanish.

Any suggestions? Thanks.
 
G

Graham Mayor

You can use the values of the characters in the replacement string e.g.

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="Senor", Forward:=True)
oRng = Replace(oRng, "n", ChrW(241))
oRng.LanguageID = wdSpanish
Loop
End With

the following is an easy way of copying the characters to the clipboard from
the document

Sub AnsiCode()
Dim myData As DataObject
Dim vChar As Variant
Dim sCode As String
Set myData = New DataObject
For Each vChar In Selection.Characters
sCode = sCode & "ChrW(" & AscW(vChar) & ") & "
Next
sCode = Left(sCode, Len(sCode) - 3)
MsgBox sCode & vbCr & vbCr & "Copied to clipboard!"
myData.SetText sCode
myData.PutInClipboard
End Sub

or you could create a table with the words you want to find in column 1 and
those that you want to replace them with in column 2
Replace the name and path of the table document in the line - sFname =
"D:\My Documents\Test\Changes.doc" with your document name and path then run
the following macro

Sub ReplaceFromTableList()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
Dim sAsk As String
sFname = "D:\My Documents\Test\Changes.doc"
Set oDoc = ActiveDocument
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False)
Set oTable = oChanges.Tables(1)
For i = 1 To oTable.Rows.Count
Set oRng = oDoc.Range
Set rFindText = oTable.Cell(i, 1).Range
rFindText.End = rFindText.End - 1
Set rReplacement = oTable.Cell(i, 2).Range
rReplacement.End = rReplacement.End - 1
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(FindText:=rFindText, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue) = True
oRng.Select
sAsk = MsgBox("Replace " & oRng, vbYesNo)
If sAsk = vbYes Then
oRng.Text = rReplacement
oRng.LanguageID = wdSpanish
End If
Loop
End With
Next i
oChanges.Close wdDoNotSaveChanges
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