PDA

View Full Version : [SOLVED:] how to open StrFile as read only



Learning)
08-20-2018, 02:41 PM
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

macropod
08-20-2018, 04:32 PM
Try, for example:


.Documents.Open (Filename:=strFolder & strFile, ReadOnly:=True, AddToRecentFiles:=False)

One wonders why your post includes most of the various Documents.Open options (twice), but you haven't bothered using any of them...

Learning)
08-20-2018, 10:45 PM
Hi Macropod, I am very new to VBA, whilst I understand machine thinking my syntax leaves much to be desired