+ Reply to Thread
Results 1 to 14 of 14

Progress bar linked to Call sub

  1. #1
    Registered User
    Join Date
    08-22-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    14

    Progress bar linked to Call sub

    Hi,

    I have a code that starts with a Sub where 5-6 Call are indicated

    Call CTNtable
    Call preprova
    Call Riassunto
    Call Finale
    Call calcoli
    Call verificapesi
    Call aggiornamentofattspedite
    Call Salvaespedisci

    I'm trying to show a progress bar with percentage indicator that updates anytime it moves to the next Sub

    For example, it starts with 0% indicator, when it starts with 'preprova' sub the indicator move to 15%, etc etc
    is it feasible?
    Thanks!

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Progress bar linked to Call sub

    Please Login or Register  to view this content.
    ?

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    Hello and Welcome to the Forum,

    Have a look at this post with a brief explanation in this post.

    Good luck.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    08-22-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Progress bar linked to Call sub

    Thanks abousetta! But if I'm not wrong that code bases the progress on the time you set... not on Call event that the macro is performing, am I right?
    If not, where should I indicate the references to each Call?

    Thanks again!

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    You would adjust the PctTotal value to the number of times you will be calling the function (e.g. 8) and replace from "start of code" to "end of code" with this:

    Please Login or Register  to view this content.
    Now the time remaining part may be off unless each one of your subs takes the same amount of time to run, but the progress bar would work fine.

    Have a look at the example in the attachment.

    abousetta
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    I should clarify, it bases on the number of times you call the function. The added bonus is it can 'guesstimate' how much longer you need to wait before your macro will be done. This is often useful for macros that can run for hours to days. If your macro runs fast then it won't really matter how much time remains and you can just ignore that part.

    Hope this helps.

    abousetta

  7. #7
    Registered User
    Join Date
    08-22-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Progress bar linked to Call sub

    I have to say my VBA knowledge is very bad... and I don't understand where I have to adjust the PctTotal Value, and I don't even understand where to copy the code you gave me; what do you mean by"start and end " of code? My code?

    Furthermore my code starts with "Application.ScreenUpdating = False" and "Application.Visible = False"; could that be a problem?

    Pratically when I launch the application, only a commandbutton is shown. When I click the button the following code starts

    Please Login or Register  to view this content.
    Considering that the user cannot see anything.. I would like to shown him just the progressbar at least (eventhough the whole code is quite fast)

    Thanks!

    Moderator Note:

    Pls use code tags around your code next time as per forum rules.
    Last edited by Fotis1991; 12-17-2013 at 09:18 AM.

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    Here is the full code. I've added extra lines for clarification:

    Please Login or Register  to view this content.
    If you copy and paste all of this code instead of the one currently in the workbook you downloaded, you should be able to see where to make the changes.

    Let me know if you have any questions.

    abousetta

  9. #9
    Registered User
    Join Date
    08-22-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Progress bar linked to Call sub

    An error message pops up:
    "Ambiguous name detected"

    and the code stops on "CTNtable" at the START OF CODE... Do you know why?

    Thanks

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    Have a look at the updated attachment. Once you enable macros and click on the button, the workbook will disappear and the userform will appear. I will keep calling your subs (in each sub I just put a call for a message box). You will be able to see that it increments the progress bar after each time you click on OK in the message box.

    abousetta
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    08-22-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Progress bar linked to Call sub

    Great! I got it!! Finally!

    I understood my mistake (very stupid mistake!)

    Thank you for your support and time!
    Last edited by clachi80; 12-17-2013 at 09:55 AM.

  12. #12
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    Remove module 14, save the file, close it and it open it again.

    When you get the ambiguous error it means that you have two subs with the same name in the workbook. This happened because you copied module2 from the example file to your own file (which already had subs with the same name).

    Let me know if you have any other problems.

    abousetta

  13. #13
    Registered User
    Join Date
    08-22-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Progress bar linked to Call sub

    The code is just perfect thank you! But I'd need your help for just one detail more.. If I can...

    I added the following code to Progressnar.Userform in order to make it trasnparent and avoid the title be shown.


    [I]Option Explicit


    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

    'Windows API calls to do all the dirty work!

    Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
    'Lots of window styles for us to play with!

    Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
    Private Const GWL_EXSTYLE As Long = (-20) 'The offset of a window's extended style
    Private Const WS_EX_LAYERED = &H80000
    Private Const LWA_COLORKEY = &H1
    Private Const LWA_ALPHA = &H2
    Private Const transColor As Long = vbCyan
    Private Const SW_SHOW As Long = 5
    Private Const WS_CAPTION As Long = &HC00000 'Style to add a titlebar

    Private Const WS_EX_DLGMODALFRAME As Long = &H1 'Controls if the window has an icon

    'Constant to identify the Close menu item

    Private Const SC_CLOSE As Long = &HF060

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub MakeFormTransparent()
    Application.ScreenUpdating = False
    Application.Visible = False


    'http://www.vbforums.com/archive/index.php/t-396385.html

    End Sub




    It works actually, but when I click the command button of the Userform4 that Calls the CallingCTNtable sub and, hence makes the Progressbar useform appears , the title bar ("percentage completed") is still shown for the very beginning and after few seconds disappears and the label updates to 37%.
    Furthermore, I am not able to see the label updates to 100% because it closes too fast

    Pratically I'd like the title bar didn't appear ever and see the 0% indication (even if for few seconds), And of course see the 100% indication too ....

    What can I do?

    Thanks again for your help!

  14. #14
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Progress bar linked to Call sub

    Hi,

    You'll need to start a new thread with this issue.

    Good luck.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Repeat call count for call center
    By arifmasum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-08-2013, 10:03 PM
  2. How to set call count according to call date and time
    By naveen4pundir in forum Access Tables & Databases
    Replies: 0
    Last Post: 04-27-2012, 02:13 AM
  3. using CALL to call methods mandatory?
    By jerryliang2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2008, 06:16 PM
  4. NEED Help - How to capture the Event's progress in Progress Bar
    By Sriram in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2006, 07:10 AM
  5. Replies: 2
    Last Post: 06-25-2006, 12:10 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1