• -Path Access Error (VBA/Word 2003)

    Author
    Topic
    #425235

    You should call Dir without arguments within the loop:

    If nReply = “y” Then
    MyFile = Dir(“a:*.*”)
    Do While MyFile “”
    Kill “a:” & MyFile
    MyFile = Dir
    Loop
    End If

    Viewing 1 reply thread
    Author
    Replies
    • #979130

      I need to add something to this macro so that I will not get a Path/File Access Error at the line — Kill “a:” & MyFile — when there is a read-only file on the diskette.
      Can someone tell me how to do that?

      ********************
      Sub SaveToDiskette()

      FileName$ = ActiveDocument.Name
      MsgBox “Please label a diskette and insert it into the A drive.” & vbCr & vbCr & “FYI: The chapter file will be closed after it has been saved to the diskette.”, vbOKOnly, “Insert Diskette”

      Dim nReply As String
      nReply = InputBox(“Do you want to delete any files that may be on this diskette BEFORE you save the chapter file to it (y or n)?” & vbCr & vbCr & “You should clean the diskette if this is the only file, or the first in a batch of files, that you want to save to this diskette.”, “Clean Diskette?”, “n”)

      If nReply = “y” Then
      Dim MyFile As String
      MyFile = Dir$(“a:*.*”)
      Do While MyFile “”
      Kill “a:” & MyFile
      MyFile = Dir$(“a:*.*”)
      Loop
      End If

      ChangeFileOpenDirectory “A:”
      ActiveDocument.SaveAs FileName:=FileName$, FileFormat:= _
      wdFormatDocument, LockComments:=False, Password:=””, AddToRecentFiles:= _
      True, WritePassword:=””, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
      False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
      SaveAsAOCELetter:=False

      ChangeFileOpenDirectory “G:ProjectsDocs”

      MsgBox “Remove the diskette from the A drive after the chapter file has closed.” & vbCr & vbCr & “Your chapter file is being sent to your network printer.”, vbOKOnly, “Remove Diskette”

      End Sub
      *************************

      Thanks,
      Jerry

    • #979134

      Hans:

      Thanks. Was that meant for the original post? I have changed the question.

      Jerry

      • #979137

        No, I replied to the original question. Try this version, I have added an error handler:

        Sub SaveToDiskette()
        Dim FileName As String
        Dim nReply As Integer
        Dim MyFile As String

        On Error GoTo ErrHandler

        FileName = ActiveDocument.Name
        MsgBox “Please label a diskette and insert it into the A drive.” & vbCr & vbCr & _
        “FYI: The chapter file will be closed after it has been saved to the diskette.”, , _
        “Insert Diskette”

        nReply = MsgBox(“Do you want to delete any files that may be on this diskette ” & _
        “BEFORE you save the chapter file to it?” & vbCr & vbCr & _
        “You should clean the diskette if this is the only file, ” & _
        “or the first in a batch of files, that you want to save to this diskette.”, _
        vbYesNo + vbQuestion + vbDefaultButton2)

        If nReply = vbYes Then
        MyFile = Dir$(“a:*.*”)
        Do While MyFile “”
        Kill “a:” & MyFile
        MyFile = Dir
        Loop
        End If

        ChangeFileOpenDirectory “A:”
        ActiveDocument.SaveAs FileName:=FileName

        ChangeFileOpenDirectory “G:ProjectsDocs”

        MsgBox “Remove the diskette from the A drive after the chapter file has closed.” & _
        vbCr & vbCr & _
        “Your chapter file is being sent to your network printer.”, , “Remove Diskette”
        Exit Sub

        ErrHandler:
        If Err = 75 Then
        ‘ Read-only file
        Resume Next
        Else
        MsgBox Err.Description, vbExclamation
        End If
        End Sub

        I have also used a MsgBox with Yes and No buttons instead of an InputBox.

    Viewing 1 reply thread
    Reply To: -Path Access Error (VBA/Word 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: