Macro for Mass Find and Replace

J

jjacobs13

That's great.

Two more questions:

1. How can the document (with the information) be selected on the fly
instead of having it set before?

2. How can the formatting be retained (i.e. bold, italicized, etc)?

Thanks once again. This is quite useful for me.
 
G

Greg Maxey

For question 1, you could use:

Sub FillArray()
Dim myArray() As String
Dim oDoc As Word.Document
Dim i As Long
Dim j As Long
Dim pRow As Long
Dim oTbl As Word.Table
Dim myFile As String
Dim PathToUse As String
With Dialogs(wdDialogFileOpen)
If .Show <> 0 Then
Set oDoc = ActiveDocument
Set oTbl = oDoc.Tables(1)
ReDim myArray(oTbl.Rows.Count - 2, 1) 'Size the array
For pRow = 2 To oTbl.Rows.Count 'Start with 2 to skip the header row
j = j + 1 'For testing only
For i = 1 To 2
myArray(pRow - 2, i - 1) = Left(oTbl.Cell(pRow, i), _
Len(oTbl.Cell(pRow, i).Range.Text) - 2)
Next
Next
oDoc.Close
Else
MsgBox "No file was opened."
End If
End With
'Testing
For pRow = 0 To j - 1
For i = 0 To 1
MsgBox myArray(pRow, i)
Next
Next
End Sub

AFAIK, you can't load formatting into an array.
 

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