Word macro print current page

B

Baghwana

Hi,

I'm trying to write a macro that would search the whole Word document and
look for a particular string in all text-boxes.

When the string is found in text-box current page should be printed.

Please for any help
Baghwana
 
G

Graham Mayor

If you do actually mean text boxes and not text form fields then

Dim sText As String
sText = InputBox("Enter text to be found", "Find Text")
With ActiveDocument
For Each aShape In .Shapes
If aShape.Type = msoTextBox Then
With aShape
If .TextFrame.HasText Then
If InStr(1, .TextFrame.TextRange, sText) Then
.TextFrame.TextRange.Select
Application.PrintOut Range:=wdPrintCurrentPage
End If
End If
End With
End If
Next aShape
End With

will print the pages with the text boxes that contain the string. If there
is more than one text box with the string, you will get a printout for each
text box.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

Baghwana

Hello,

thank you Graham very much. Macro works perfectly.

You helped me a lot.
Baghwana
 

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