How do we interact with VBA code during the runtime?

E

Edward

Hi Everybody,
I have a userform that runs a code to check the font for each word and
writes the font name in a textbox on my form , now I want to stop VBA code
when it finds a specific font and wait for the user to click on a button on
the userform asking skip or delete and after user makes his choice VBA code
continues to check the rest of the words until it finds another specific font
or gets to the end of document. Is this possible?
 
G

Greg Maxey

I am not sure I fully understand your process, but you will probably need to
use a modeless UserForm.


Something like this:

In the calling project:

Sub CallUF()
Dim oFrm As UserForm1
Set oFrm = New UserForm1
oFrm.Show vbModeless
End Sub

In the Userform:

Option Explicit
Dim oWord As Word.Range
Dim oRng As Word.Range

Private Sub UserForm_Initialize()
For Each oWord In ActiveDocument.Range.Words
Me.TextBox1.Text = oWord.Font.Name
If oWord.Font.Name = "Arial" Then
oWord.Select
Exit For
End If
Next oWord
End Sub


Private Sub cmdSkip_Click()
Set oRng = ActiveDocument.Range
oRng.Start = oWord.End
For Each oWord In oRng.Words
Me.TextBox1.Text = oWord.Font.Name
If oWord.Font.Name = "Arial" Then
oWord.Select
Exit For
End If
Next oWord
End Sub

Private Sub cmdDelete_Click()
Set oRng = ActiveDocument.Range
oRng.Start = oWord.End
oWord.Delete
For Each oWord In oRng.Words
Me.TextBox1.Text = oWord.Font.Name
If oWord.Font.Name = "Arial" Then
oWord.Select
Exit For
End If
Next oWord
End Sub

Private Sub UserForm_Initialize()
For Each oWord In ActiveDocument.Range.Words
Me.TextBox1.Text = oWord.Font.Name
If oWord.Font.Name = "Arial" Then
oWord.Select
Exit For
End If
Next oWord
End Sub
 
E

Edward

Thanks Greg I think that will do the trick , I will check the code in a few
days and will ask furtur questions if I get into a trouble ... Thanks again:
 

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