Consulting

Results 1 to 3 of 3

Thread: how to open StrFile as read only

  1. #1

    how to open StrFile as read only

    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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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...
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Hi Macropod, I am very new to VBA, whilst I understand machine thinking my syntax leaves much to be desired

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •