5
562487
From numerous newsgroups I'm able to piece together the below VBA
macro. The document I launch the macro from has a table with 2
columns, the first with old data and the second with new data. The
dialog box opens but I can't seem to pass the file name of what I just
opened to ChangeDoc variable. The line ChangeDoc = Documents.Open
blows up. How can I fix this?
562487
My intentions are listed:
a. Launch macro
b. Open diaglog box to select a *.seq file (text file)
c. Copy contents in a table in the Word document to matching words
in the Opened file
d. Close the file
Option Explicit
Sub ParseIt()
'
'
Dim ChangeDoc As Document, RefDoc As Document
Dim ctable As Table
Dim oldpart As Range, newpart As Range
Dim i As Long
Dim a As Long
Set RefDoc = ActiveDocument
With Dialogs(wdDialogFileOpen)
.Name = "*.seq"
.Display
If Right(LCase(.Name), 3) <> "seq" Then
MsgBox "You can only open files with a "".seq"" extension."
Else
ChangeDoc = Documents.Open
End If
End With
Set ctable = ChangeDoc.Tables(1)
RefDoc.Activate
For i = 2 To ctable.Rows.Count
Set oldpart = ctable.Cell(i, 1).Range
oldpart.End = oldpart.End - 1
Set newpart = ctable.Cell(i, 2).Range
newpart.End = newpart.End - 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute findText:=oldpart, ReplaceWith:=newpart,
Replace:=wdReplaceAll, MatchWildcards:=False, Forward:=True,
Wrap:=wdFindContinue
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub
macro. The document I launch the macro from has a table with 2
columns, the first with old data and the second with new data. The
dialog box opens but I can't seem to pass the file name of what I just
opened to ChangeDoc variable. The line ChangeDoc = Documents.Open
blows up. How can I fix this?
562487
My intentions are listed:
a. Launch macro
b. Open diaglog box to select a *.seq file (text file)
c. Copy contents in a table in the Word document to matching words
in the Opened file
d. Close the file
Option Explicit
Sub ParseIt()
'
'
Dim ChangeDoc As Document, RefDoc As Document
Dim ctable As Table
Dim oldpart As Range, newpart As Range
Dim i As Long
Dim a As Long
Set RefDoc = ActiveDocument
With Dialogs(wdDialogFileOpen)
.Name = "*.seq"
.Display
If Right(LCase(.Name), 3) <> "seq" Then
MsgBox "You can only open files with a "".seq"" extension."
Else
ChangeDoc = Documents.Open
End If
End With
Set ctable = ChangeDoc.Tables(1)
RefDoc.Activate
For i = 2 To ctable.Rows.Count
Set oldpart = ctable.Cell(i, 1).Range
oldpart.End = oldpart.End - 1
Set newpart = ctable.Cell(i, 2).Range
newpart.End = newpart.End - 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute findText:=oldpart, ReplaceWith:=newpart,
Replace:=wdReplaceAll, MatchWildcards:=False, Forward:=True,
Wrap:=wdFindContinue
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub