• Wait Until File Attribute Changes

    Author
    Topic
    #462618

    I have VBA code that changes a file’s attribute from vbHidden to vbNormal and then proceeds to the next line of code.

    My challenge is that the code continues prior to the file attribute is changed. This is simply a timing issue. How does one prevent the code from continuing until the file attribute changes?

    Thanks,
    John

    Viewing 0 reply threads
    Author
    Replies
    • #1178090

      Does it help if you insert a line

      DoEvents

      between the two instructions?

      If not, you could insert a loop

      Code:
      Do While (file is hidden)
        DoEvents
      Loop
      • #1178095

        Hans,

        It’s still happening.

        My code example is:

        [codebox]’File Attributes
        FileAttribute = GetAttr(sPathOfSourceFile & strFileName) And vbHidden

        If FileAttribute = 2 Then
        SetAttr (sPathOfSourceFile & strFileName), vbNormal
        Do While GetAttr(sPathOfSourceFile & strFileName) 0
        DoEvents
        Loop
        End If
        [/codebox]

        Regards,
        John

        • #1178114

          I’m sorry, I can’t explain that. What happens if you single-step through the code?

          • #1178208

            I’m sorry, I can’t explain that. What happens if you single-step through the code?

            Stepping through the code provides enough time for the file attribute to change. All other lines of code run as expected.

            Seem to be a timing difference in seconds.

            Regards,
            John

            • #1178224

              That was to be expected. But I still don’t understand why the Do While loop doesn’t work…

    Viewing 0 reply threads
    Reply To: Wait Until File Attribute Changes

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

    Your information: