The includetext fields are written to the document with the line:
With Selection
.TypeText Text:="INCLUDETEXT " & Chr(34) & strPath &
Format(strCount, "00") _
& strMonth & strYear & "\\" & strDocName & Chr(34)
End With
strYear is the year
styMonth is the month
and Format(strCount, "00") is the incremented day
you can change the order thus:
With Selection
.TypeText Text:="INCLUDETEXT " & Chr(34) & strPath _
& strYear & strMonth & Format(strCount, "00") & _
"\\" & strDocName & Chr(34)
End With
The following contains the code for both versions (also some additional
prompts in which you will have to change the defaults - document name and
path - to your own requirements)
Sub PrepReport()
Dim strPath As String
Dim strDocName As String
Dim strMonth As String
Dim strCount As Long
Dim strYear As String
Dim strDays As String
Dim strLeap As String
Documents.Add
'enter path of containing folder
strPath = InputBox("Enter Path in format: " & vbCr & _
"Drive:\\path\\", "Path", "D:\\My Documents\\Test\\")
'enter name of document
strDocName = InputBox("Enter Name of document" & vbCr & _
"in format: docname.ext", "Document name", "Settings.txt")
strMonth = InputBox("Enter Month in format: " & Format(Date, "MM"), _
"Month", Format(Date, "MM"))
If strMonth = "04" Or strMonth = "06" Or strMonth = "09" _
Or strMonth = "11" Then
strDays = 30
Else: strDays = 31
End If
If strMonth = "02" Then
strLeap = InputBox("Is this a leap year? ", "February", "NO")
If strLeap <> "NO" Then
strDays = 29
Else: strDays = 28
End If
End If
strYear = InputBox("Enter Year in format: " & Format(Date, "yy"), _
"Year", Format(Date, "yy"))
For strCount = 1 To strDays
If strCount <> 1 Then
Selection.TypeParagraph
End If
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
With Selection
.TypeText Text:="INCLUDETEXT " & Chr(34) & strPath _
& Format(strCount, "00") & strMonth & strYear _
& "\\" & strDocName & Chr(34)
End With
' With Selection
' .TypeText Text:="INCLUDETEXT " & Chr(34) & strPath _
& strYear & strMonth & Format(strCount, "00") & _
"\\" & strDocName & Chr(34)
' End With
Selection.EndKey Unit:=wdLine
Next
With Selection
.WholeStory
.Fields.Update
.HomeKey
End With
End Sub
yes..that's it!
your code works perfectly!
[quoted text clipped - 79 lines]