Hello all
I am trying to write code to open and print numerous files that have a common component in the file name
my code I have thus far is as below, I can't figure out how to include the sections in red without it being an error, all help much appreciated
Sub BatchPrintWordDocuments()
Dim objWordApplication As New Word.Application
Dim strFile As String
Dim strFolder As String
Dim strDate As String
strDate = InputBox("Enter the date to print ddmmyy")
For x = 1 To 16
strFolder = "W:\Network Movement\Train Control & Authorities\Train Advices and Bulletins\Authorities\Train Advices\Sent\2018"
strFile = Dir(strFolder & strDate & "l*.doc*", vbNormal)
, ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
Next
strFolder = "W:\Network Movement\Train Control & Authorities\Train Advices and Bulletins\Authorities\Train Advices\Sent\2018"
strFile = Dir(strFolder & strDate & "L*.doc*", vbNormal)
, ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
While strFile <> ""
With objWordApplication
.Documents.Open (strFolder & strFile)
'batch print files here
End With
strFile = Dir()
Wend
Set objWordApplication = Nothing
End Sub