Hi,
As you said
"The macro in the link works with the Excel workbook directly, without the need for you to use Word tables. That should make your work far more efficient. "
I thought my purpose was clear. So I’ll try to express myself neatly:
The macro bellow requires LCase conversion, but my spreadsheets are all written in lowercase, so now I need a new macro to capitalise the first character, excluding possible wildcards, such as
, of the two columns of my "abbreviations excel spreadsheet".
Once this is done, I'll copy and paste this capitalised two-column table into a word document, namely C:\Users\Win7\Desktop\macro.docx,
which I'll finally use for the macro bellow
Sub ReplaceFromTableList()
Application.ScreenUpdating = False
Dim Doc As Document, Rng As Range, i As Long, Tbl As Table
Dim sFname As String, StrFnd As String, StrRep As String
sFname = "C:\Users\Win7\Desktop\macro.docx" 'The table document
Set Rng = ActiveDocument.Range
Set Doc = Documents.Open(FileName:=sFname, Visible:=False)
Set Tbl = Doc.Tables(1)
With Rng.Find
.MatchWildcards = True
.Wrap = wdFindContinue
For i = 1 To Tbl.Rows.Count
.ClearFormatting
.Replacement.ClearFormatting
StrFnd = Split(Tbl.Cell(i, 1).Range.Text, vbCr)(0)
StrRep = Split(Tbl.Cell(i, 2).Range.Text, vbCr)(0)
.Text = StrFnd
.Replacement.Text = StrRep
If Split(Tbl.Cell(i, 3).Range.Text, vbCr)(0) <> "" Then
Set FntFnd = Tbl.Cell(i, 4).Range.Characters(1).Font
.Font.Bold = FntFnd.Bold
.Font.Italic = FntFnd.Italic
.Font.Underline = FntFnd.Underline
End If
If Split(Tbl.Cell(i, 4).Range.Text, vbCr)(0) <> "" Then
Set FntRep = Tbl.Cell(i, 4).Range.Characters(1).Font
With .Replacement
.Font.Bold = FntRep.Bold
.Font.Italic = FntRep.Italic
.Font.Underline = FntRep.Underline
End With
End If
.Execute Replace:=wdReplaceAll
.Text = LCase(StrFnd)
.Replacement.Text = LCase(StrRep)
.Execute Replace:=wdReplaceAll
Next i
End With
Doc.Close wdDoNotSaveChanges
Application.ScreenUpdating = True
End Sub