I stopped trying to get to the end and worked through the code. Its still not exactly what I want but it does work.
This puts the TOC on page one. when I want to set the range as page two. (ill work on that when I get the chance)
Code:
Sub openword()
Dim FSO As Object
Dim fPath As String
Dim myFolder, myFile
Dim wdApp As Object 'Late Binding
Set FSO = CreateObject("Scripting.FileSystemObject")
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then fPath = .SelectedItems(1) & "\"
End With
On Error Resume Next
Set myFolder = FSO.GetFolder(fPath).Files
If Err.Number <> 0 Then 'Cancel button clicked.
Exit Sub
End If
For Each myFile In myFolder
If LCase(myFile) Like "*.doc" _
Or LCase(myFile) Like "*.docx" Or LCase(myFile) Like "*.docm" Then
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word not yet running
Set wdApp = CreateObject("Word.Application")
End If
wdApp.Documents.Open CStr(myFile)
Call secondSubRoutine
wdApp.Visible = True
Set wdApp = Nothing
End If 'LCase
Next myFile
End Sub
Sub secondSubRoutine()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
oRng.Collapse
With ActiveDocument
.TablesOfContents.Add Range:=oRng, RightAlignPageNumbers:= _
True, UseHeadingStyles:=False, IncludePageNumbers:=True, AddedStyles _
:="SpecTOC,1", UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
End Sub