Adding a slick progress bar to my macro

J

Josh

I got the code to add a progress bar from the Word MVP website (http://
word.mvps.org/FAQs/Userforms/CreateAProgressBar.htm) but I wanted to
apply it to the awesome code Bear created for me in a previous post.
I was deleting and/or replacing checkboxes in a document. I counted
all the check boxes in my document, there are 273 of them. I inserted
the code into the MVP code and my progress bar actually goes
backwards. I need to know how to declare the number of checkboxes
correctly so the bar will work correctly. Here is what I have.

Option Explicit
Private Sub UserForm_Activate()
Dim i As Integer
ToggleProtectDoc (unlocks document)
Me.Repaint
For i = ActiveDocument.FormFields.Count To 1 Step -1
With ActiveDocument.FormFields(i)
If .Type = wdFieldFormCheckBox Then
If .CheckBox.Value = True Then
.Range = "X"
Else
.Delete
End If
End If
End With
Label1.Width = i / 7
Frame1.Repaint
Next i
Unload Me
End Sub
 
R

Russ

Josh,
Try substitution below.

I got the code to add a progress bar from the Word MVP website (http://
word.mvps.org/FAQs/Userforms/CreateAProgressBar.htm) but I wanted to
apply it to the awesome code Bear created for me in a previous post.
I was deleting and/or replacing checkboxes in a document. I counted
all the check boxes in my document, there are 273 of them. I inserted
the code into the MVP code and my progress bar actually goes
backwards. I need to know how to declare the number of checkboxes
correctly so the bar will work correctly. Here is what I have.

Option Explicit
Private Sub UserForm_Activate()
Dim i As Integer
ToggleProtectDoc (unlocks document)
Me.Repaint
For i = ActiveDocument.FormFields.Count To 1 Step -1
With ActiveDocument.FormFields(i)
If .Type = wdFieldFormCheckBox Then
If .CheckBox.Value = True Then
.Range = "X"
Else
.Delete
End If
End If
End With
Label1.Width = i / 7 Label1.Width = i - i / 7
Frame1.Repaint
Next i
Unload Me
End Sub
 
R

Russ

Josh,
If that didn't work, try the three changes below.
Trying to get a backwards backwards = forward ;)
You do, as mentioned elsewhere before, want to leave the routine deleting
backwards.
 
J

Josh

The Label1.Width = i - i / 7 solution is pretty cool. The progress
bar starts out completely full and gets smaller. I like it, it's
different from everything else out there. Thanks a ton!
 
R

Russ

Purely serendipitous, because I wasn't testing and I actually hadn't used
the progress bar code before, but I remembered that it was using a label as
a visible cue.
Glad it work out for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top