Return current running code line

elbayedh

New Member
Joined
Nov 24, 2014
Messages
3
Hello,

Here is the story:
I am trying to create a progress bar that it's max is the number of code lines in the macro's module-
Code:
C = ActiveWorkbook.VBProject.VBComponents("macro1").CodeModule.ProcCountLines("module", vbext_pk_Proc)

This will return how many lines of code I have, thus:
Code:
Userform1.ProgressBar.Max = C

Now, what I am trying to do is something like this, which will be running along side of the module...
Code:
UserForm1.ProgressBar.value = CURRENT RUNNING LINE NUMBER

Any ideas???

Thank you in advance guys :)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
There isn't a feature for this in VBA, but a work around could be a Public Variable, CurrentCodeLocation

And putting
Code:
CurrentCodeLocation = CurrentCodeLocation + 1
every other line might help you.
 
Upvote 0
I was thinking about that, but there are about 1154 lines of code in one module and there are 4!!!
The amount time it would take is long to do.

I had another idea but I don't know how it can be done.

Code:
For i = 1 To C
Call ActiveWorkbook.VBProject.VBComponents("Macro1").CodeModule.ProcCountLines("Module", vbext_pk_Proc).Lines(i, 1)
UserForm1.ProgressBar.Value = UserForm1.ProgressBar.Value + 1
Next i

This would work I think only if I can make it run the command!
 
Upvote 0
Leave the code module alone. (The call statement won't work, you can't call subs line by line). Don't bother with it.

Find some key points in your code and advance the progress bar at those points.
Note that some lines take longer to excicute than others.


Code:
For i = 1 to 1000
    ' some code
Next i
Call IncreaseBarLength

For i = 1 to 10000
    'Some other code
    If (i Mod 1000) = 0 The Call IncreaseBarLength
Next i
 
Upvote 0
That's a bummer, thought I can out smart the VBA lol

I have done what you have suggested, but I was looking for a way to make it cleaner, there are about 8 loops that take a wile to complete and they + 1 the value of the progress bar. but of curse the remaining time it will be still.

So there isn't a better way to do it? :'(
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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