Vba File Copy Progress Bar

As the copying of streams is more an action than an object and the action has not to be extended in the way of OOD, I think the functional approach is more natural. Progress statistics. Now the progress can be tracked, but displaying only the number of bytes copied in contrast to the number of bytes which will be copied, is not enough for most. Show progress meter when copying files. I am currently using the FileCopy command to copy files in part of my excel vba program, the problem i am having is that the files being copied can often be upto 10GB and while the file is being copied excel appears to the user to have 'hung' and often they will try to force close excel using taskmanager. How to use Progress Bar in excel Macro (VBA) Progress bar is nothing but a placeholder, where you see the Progress of the operation which is getting performed. Like Visual Studio there is NO already built progress bar in Excel Macro (VBA), which you can use it as an object and it will act like a Progress bar. Try this: Start a new Windows Forms application and replace the code on Form1 with. Imports System.Net Imports System.IO Public Class Form1 Protected Overrides Sub OnLoad(e As EventArgs) MyBase.OnLoad(e) CopyBtn.Text = 'Copy File' CopyBtn.Parent = Me ProgBar.Left = CopyBtn.Right End Sub Dim WithEvents CopyBtn As New Button Dim ProgBar As New ProgressBar Dim WithEvents FileCopier As New.

Some VBA Macros run for ages – be it minutes or even hours. If we optimized our VBA Macro to the fullest there is often not much more you can do to change that. Usually what is irritating is waiting for VBA Macro code completion. Sitting by your desk is a waste of time – why not tell Excel/Access to let you know when the code has completed? Today we will explore such tools as the VBA Status Bar, VBA Progress Bar, Sound Notifications in VBA and Sending Email Alerts from VBA.

VBA Progress Bar

Progress Bars are ubiquitous anywhere anything takes more than a couple of seconds to complete. So why doesn’t VBA have a native Progress Bar – beats me.

To add a VBA Progress Bar to your Visual Basic for Applications macro read my post here.

Vba File Copy Progress Bar

Excel Status Bar

The VBA Status Bar is a panel that appears at the bottom of your Excel (or Access) Workbook. It is basically a Text Box to which you can display any non-blocking (non-modal) Message to your users.

Showing a Message in the VBA Status Bar

To show a message in the VBA Status Bar we need to Enable it using Application.DisplayStatusBar:

Hiding the VBA Status Bar

The VBA Status Bar when displayed, will remain displayed until ordered otherwise. It is best to hide and clean it after code execution completion:

Sound Notifications in VBA

What if you are away from your Screen, getting a Coffee or simply chatting with a colleague or getting on with our tasks stressed that we might miss that moment when our VBA Macro completes its task. Well why not introduce a Sound Notification? Let Excel or Access run a Sound to inform you that your Visual Basic for Applications macro has finally completed.

Playing a Sound in VBA

Playing a Sound in VBA is easy. Just add the below code snippet to a VBA Module:

It will play the Chimes.wav sound Once.

What if you don’t hear it? Running it once might obviously be not enough…

VBA Sound Alarm

The best approach is to create a VBA Sound Alarm that will run in a loop until we Turn it Off manually. What we will need is a Non-Modal UserForm as a pop-up to ask to stop the alarm.

First the macro code:

What happens here?:

  • I am measuring the execution time with the startTime and execTime variables
  • I am using the stopPlaying global VBA Variable to Turn Off the Alarm from our Alarm UserForm changes this value to True
  • I am displaying the AlarmForm with the Turn Off Alarm button

And now our AlarmForm code:

The result:

VBA Send Email Notification

Vba File Copy Progress Bar Examples

Lastly when we are on the run and leaving our Workstation to process our VBA Macro remotely we might appreciate an email from Excel saying: Hey there! I just completed running the Macro!

You can find the code for the SendEmailFromOutlook function in my post here.

We might want to spice things up with maybe sending also the time it took to complete the macro:

Cool right? Makes the VBA Message Box hide in shame doesn’t it? The email should look like this:

Related posts:
  • VB.Net Basic Tutorial
  • VB.Net Advanced Tutorial
  • VB.Net Useful Resources
  • Selected Reading

It represents a Windows progress bar control. It is used to provide visual feedback to your users about the status of some task. It shows a bar that fills in from left to right as the operation progresses.

Let's click on a ProgressBar control from the Toolbox and place it on the form.

The main properties of a progress bar are Value, Maximum and Minimum. The Minimum and Maximum properties are used to set the minimum and maximum values that the progress bar can display. The Value property specifies the current position of the progress bar.

The ProgressBar control is typically used when an application performs tasks such as copying files or printing documents. To a user the application might look unresponsive if there is no visual cue. In such cases, using the ProgressBar allows the programmer to provide a visual status of progress.

Properties of the ProgressBar Control

The following are some of the commonly used properties of the ProgressBar control −

Sr.No.Property & Description
1

AllowDrop

Overrides Control.AllowDrop.

2

BackgroundImage

Gets or sets the background image for the ProgressBar control.

3

BackgroundImageLayout

Gets or sets the layout of the background image of the progress bar.

4

CausesValidation

Gets or sets a value indicating whether the control, when it receives focus, causes validation to be performed on any controls that require validation.

5

Font

Gets or sets the font of text in the ProgressBar.

6

ImeMode

Gets or sets the input method editor (IME) for the ProgressBar.

7

ImeModeBase

Gets or sets the IME mode of a control.

8

MarqueeAnimationSpeed

Gets or sets the time period, in milliseconds, that it takes the progress block to scroll across the progress bar.

9

Maximum

Gets or sets the maximum value of the range of the control.v

10

Minimum

Gets or sets the minimum value of the range of the control.

11

Padding

Gets or sets the space between the edges of a ProgressBar control and its contents.

12

RightToLeftLayout

Gets or sets a value indicating whether the ProgressBar and any text it contains is displayed from right to left.

13

Step

Gets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar.

14

Style

Gets or sets the manner in which progress should be indicated on the progress bar.

15

Value

Gets or sets the current position of the progress bar.v

Methods of the ProgressBar Control

The following are some of the commonly used methods of the ProgressBar control −

Sr.No.Method Name & Description
1

Increment

Increments the current position of the ProgressBar control by specified amount.

2

PerformStep

Increments the value by the specified step.

3

ResetText

Resets the Text property to its default value.

4

ToString

Returns a string that represents the progress bar control.

Events of the ProgressBar Control

The following are some of the commonly used events of the ProgressBar control −

Sr.No.Event & Description
1

BackgroundImageChanged

Occurs when the value of the BackgroundImage property changes.

2

BackgroundImageLayoutChanged

Occurs when the value of the BackgroundImageLayout property changes.

3

CausesValidationChanged

Occurs when the value of the CausesValidation property changes.

4

Click

Occurs when the control is clicked.

5

DoubleClick

Occurs when the user double-clicks the control.

6

Enter

Occurs when focus enters the control.

7

FontChanged

Occurs when the value of the Font property changes.

8

ImeModeChanged

Occurs when the value of the ImeMode property changes.

9

KeyDown

Occurs when the user presses a key while the control has focus.

10

KeyPress

Occurs when the user presses a key while the control has focus.

11

KeyUp

Occurs when the user releases a key while the control has focus.

12

Leave

Occurs when focus leaves the ProgressBar control.

13

MouseClick

Occurs when the control is clicked by the mouse.

14

MouseDoubleClick

Occurs when the user double-clicks the control.

15

PaddingChanged

Occurs when the value of the Padding property changes.

16

Paint

Occurs when the ProgressBar is drawn.

17

RightToLeftLayoutChanged

Occurs when the RightToLeftLayout property changes.

18

TabStopChanged

Occurs when the TabStop property changes.

19

TextChanged

Occurs when the Text property changes.

Example

Copy

In this example, let us create a progress bar at runtime. Let's double click on the Form and put the follow code in the opened window.

Vba File Copy Progress Bar Example

When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window −

Vba File Copy Progress Bar Excel