ProgressBar to show large file copy progress

I have a procedure that copies a large file (approx. 4MB) from a network server to a local workstation.  The problem I'm having is the user gets impatient and thinks the computer is locked up.  I'd like to use the progress bar to show the status of the file being copied.  My plan was to check the filesize of the file to be copied, assign that to my progressbar.max property.  Then use a timer to check the filesize of the destination file every 1 second.  Then assign that to the progressbar.value property.  Unfortunately, the timer event never fires until the file copy is complete.  Can anyone offer any suggestions.  
Who is Participating?
There are two soultions :
1- The most beautiful : use the features of the Windows 95 API, and particulary the function SHFileOperation.
 If you want, I can send you sample code (give me your e-mail)

2- Rewrite the copy function adding a timer and a progress bar.
I have a part of that code (give me your e-mail)

If I was you, I will choose the first solution
SekansAuthor Commented:
I would prefer to use the API.  Please send to

I'm curious, how could I rewrite the copy function?


To rewrite a vba function, make a BAS module, and just rewrite the function.  

public sub FileCopy(szSource as string, szDest as string)
  'implement copy here
  msgbox "Guess what, I am going to copy a file now"
  vba.filecopy szSource, szDest
end sub
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SekansAuthor Commented:
waty, what do I do with the file you sent me?

SekansAuthor Commented:
I don't understand how I can use this to report the progress of a large file copy.  Please ellaborate.

For waty,
I will also like to see how does it work. Here is my email

Please send me the code.

Using this API, you don't have to use a progress bar. The progress bar is on the window used to copy (coming from the API.

If you still want your own progress bar, you have to rewrite your copy function.

You have a lot of other functions (see in the project I sent you)

To use the API, do as follow :

' *** Delcaration
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Boolean
    hNameMappings As Long
    lpszProgressTitle As String 'Used only if FOF_SIMPLEPROGRESS specified
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Sub CopyFile(sFile as string, sDest as string)


    FileOp.wFunc = FO_COPY
    FileOp.pFrom = sFile & Chr$(0)
    FileOp.pTo = sDest & Chr$(0)

    If SHFileOperation(FileOp) <> 0 Then
        MsgBox "Did not complete operation successfully."
    End If

End Sub

Hai Waty,
I have used a Progress Bar. But how to use API call. Can you pls. send me the code.
my email is
Hi all,
There are a few things you should be aware of when using this function (I don't want to offend anybody with these comments, just give some extra information).

First of all, it doesn't let you specify a user-defined callback function to show the progressbar with. With this function you have only two choices: you use the progress-dialogbox supplied with the explorer or you don't show a thing at all (FOF_SILENT).

The problem with the progress-dialog of Explorer is the "Cancel" button. You cannot get rid of it in a "normal" way, unless you work with more than one thread and let another thread monitor the progressbar (and/or disable the "cancel" button as soon as it appears), but that's very unhandy.

Another problem rises when trying to use pszProgressTitle. On Win95/98 it's just ignored (even when FOF_SIMPLEPROGRESS is specified) and on WinNT you will end up with "cannot read from" access violation and your program will be closed.

Then I haven't even talked about the messageboxes with errors that can rise when using that function. You can suppress them, but that usually means that you have to do something about the error by yourself. Meaning that you must process the returncode of SHFileOperation and (most of the time) call SHFileOperation again, resulting in a loss of valuable time.

If you really need your own progressbar I would suggest that you make a small procedure that cuts the large file in small pieces and copies them one by one. Using an array, a loop and DoEvents you will be able to display a progressbar while copying. The last step, off course, is joining the parts together (or do it at each step - that saves time at the end).
Doing it this way you can have full control, AND you have a function you can use in several other apps as well.

Regards, Abel

PS: When you copy the SHFileOperation function from the API-viewer, make sure you delete the leading space in the Alias-string. It says " SHFileOperationA" and it should be "SHFileOperationA". Otherwise you won't be able to call the function.
SekansAuthor Commented:
The points are yours.  You supplied a great answer to my question.  Thanks for the help.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.