How to provide a file progress bar when downloading a large file

tmd63

New Member
Joined
Feb 21, 2014
Messages
40
Office Version
  1. 2013
  2. 2003 or older
Platform
  1. Windows
I have this code that opens a workbook on a local website on our intranet and then copies the sheet into a local file.

Code:
    Workbooks.Open ("http://teamspace.****.com/sites/****/****/Shared%20Documents/Lookup.xls")

    LastRow = ActiveSheet.Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
    ActiveSheet.Range("A1:M" & LastRow).Select
    Selection.Copy
    
    Application.DisplayAlerts = False
    
    ActiveWorkbook.Close

But this is a large file and the copy takes time to work. Is there some way of displaying a file copy progress bar? Note this is part of a much larger code and I need to insert the progress in here instead of putting all the code inside a progress form as I have seen done before.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Instead of a progress bar, you could use the StatusBar to update progress with. It would be less coding to do and easier to insert into your existing code.

Search online for
Code:
Application.StatusBar
, you should find lots of examples.

One way to speed the above up is to make a local copy of the workbook and then export the data out of it.

I have similar problems at work, when opening files from none EMEA based locations just to export data and found copying the file first, (say to C:\Temp\) made a noticeable improvement.
 
Last edited:
Upvote 0
I tried searching and nothing appears to solve my issue.
 
Upvote 0
Oh. I was missing some code here.

Code:
   Workbooks.Open ("http://teamspace.****.com/sites/****/****/Shared%20Documents/Lookup.xls")

    LastRow = ActiveSheet.Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
    ActiveSheet.Range("A1:M" & LastRow).Select
    Selection.Copy
    
    Application.DisplayAlerts = False
    
    ActiveWorkbook.Close
    
    Worksheets("Lookup").Select
    ActiveSheet.Range("A1").Select
    Worksheets("Lookup").Paste

I have nothing here to provide a reference to the progress of the copy to be able to code a progress bar, so how can I get a progress bar to show the code is still running?
 
Upvote 0
I think you missed my point, I am recommending forget the progress bar entirely and use the StatusBar (a native feature to VBA) to inform the user of the copying status.

On a separate point, if you copied the file to a local destination to where the macro is running from, it will open the file much faster, than trying to open it from a sharepoint location. You can always delete the copied file afterwards.

Combining the two above, if you copy the file to a local destination, you may find you do not need a progress bar at all, which would save you having to insert code to provide something for your end-user that may not be needed.
 
Upvote 0
Hi Jack,
Sorry, I did see the statusbar but still couldnt find how to do it without providing a percentage of the file information. There doesnt appear to be a method that generically give a status progress.

Unless I am not searching correctly. Can you provide any information?

Most of the people that will use this excel sheet have little space available to copy the file locally, so I have to make it robust for this type of situation. I dont want to get into the same issue as Google play where it refuses to download because the C drive is full despite the application being located on a D drive that has space. :)
 
Upvote 0
While the file is opening, you can't display a statusbar which changes as it's opening because the macro pauses until it's done opening. At best, you'd see 0% then 100% (which takes a statusbar message before opening and one afterwards) which is of no help. Maybe just give a "Please wait while the file opens" message.
 
Upvote 0
As Bob points out, VBA executes sequentially, it will open the workbook then pause and won't execute the 'next' line of code until the workbook is opened and control is handed back to VBA.

Statusbar code suggestion:
Code:
Application.StatusBar = "Please wait whilst file opens, this may take some time.
 
Last edited:
Upvote 0
Thanks. Not quite what I had in mind, but I understand the reason it cannot be done.
Looks like I will have to use the status bar and ask the user to wait. It is a pity there is not an windows API call or code that could be used to provide a download bar.
 
Upvote 0
You could look into using an ADO connection via VBA, it should read the data in faster (bypasses having to open and close the file) but I do not know enough about this yet to recommend code.

Personally though, I still think you should consider filecopy solution - depending on how quickly you want to implement this/your Users need the functionality of the full code.

You can copy to other locations, it doesn't have to be C:\Temp. D:\, E:\ anywhere you have a local place to copy the file to.

Have you tried to time the difference between opening a file from your sharepoint vs opening same file locally?
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top