OK, it's obvious I need to find a good VBA for Word book.... any
suggestions????
Below is the code I have so far pieced together, may not be the most
efficent, but so far I am able to get the section of text selected that I am
needing, still can't assign it to ptarget to get it into my other document...
What am I not doing???
Sub Create_New_Templates()
Dim MyFile As String
Dim Counter As Long
Dim AppraisalDoc As New Document
Dim curDoc As Document
Dim SourceDocRg As Range
Dim oDestRg As Range
Dim pH1 As Range
Dim pH2 As Range
Dim pTarget As Range
Dim lHeading1, lHeading2 As Integer
Const tHeading1 = "SUMMARY"
Const tHeading2 = "JOB QUALIFICATIONS"
Const strPath = "C:\workarea\testing\"
lHeading1 = Len(tHeading1)
lHeading2 = Len(tHeading2)
'*****************************************************
'Read directory for filenames into DirectoryListArray
'*****************************************************
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
MyFile = Dir$(strPath & "*.doc")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop
ReDim Preserve DirectoryListArray(Counter - 1)
'*****************************************************
'Start looping through files, opening, reading data
'*****************************************************
For Counter = 0 To UBound(DirectoryListArray)
Set curDoc = Documents.Open(strPath & DirectoryListArray(Counter))
MsgBox strPath & DirectoryListArray(Counter)
Set pH1 = curDoc.Range
Set pH2 = curDoc.Range
'Set oDestRg = IssuesDoc.Range
ResetSearch
With pH1.Find
.Text = tHeading1
.MatchCase = True
.Execute
If .Found Then
'MsgBox pH1.Find.Text & " Found At " & pH1.End
ResetSearch
With pH2.Find
.Text = tHeading2
.MatchCase = True
.Execute
If .Found Then
MsgBox pH2.Find.Text & " Found At " & pH2.End
End If
End With
MsgBox curDoc.Range(pH1.End + 1, pH2.End - lHeading2)
pTarget = ActiveDocument.Range(Start:=pH1.End + 1,
End:=pH2.End - lHeading2)
End If
End With
curDoc.Close
Next
End Sub
Thanks to all....
Jay Freedman - 24 Jan 2005 02:08 GMT
Although you don't say exactly what happens, I'll guess you're getting
the error message about "object or With missing".
When you make a direct assignment to a Range or any other kind of
object (as opposed to a simple data type such as Integer or String),
you have to use the Set keyword:
Set pTarget = ActiveDocument.Range(...
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
>OK, it's obvious I need to find a good VBA for Word book.... any
>suggestions????
[quoted text clipped - 85 lines]
>
>Thanks to all....