Results 1 to 5 of 5
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: -Path Access Error (VBA/Word 2003)

    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

  2. #2
    Lounger
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    -Path Access Error (VBA/Word 2003)

    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

  3. #3
    Lounger
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: -Path Access Error (VBA/Word 2003)

    Hans:

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

    Jerry

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: -Path Access Error (VBA/Word 2003)

    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.

  5. #5
    Lounger
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: -Path Access Error (VBA/Word 2003)

    Hans:

    Thanks for your help.

    Jerry

Posting Permissions

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