View Single Post
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Ed Ed is offline
external usenet poster
 
Posts: 217
Default Creating a search function w/in word and hyperlinked documents

Hi Bcfd-IT3,

I don't get the "four levels of transparency" that I can cycle through by double clicking an empty area of the form.


- If it's working as it's supposed to (possibly a big if), you should be
able to alter the transparency by double-clicking a blank area of the form
itself, not the textbox or any of the buttons or the title bar, but, for
example, the bit of the form below the buttons.

I don't get the dragging and dropping the search dialog box to my
preferred location.


- What should happen when you drag the form somewhere and click the Save
button is that it should "remember" where on the screen it was when you
clicked Save, and next time the form opens it should open at the same
location on the screen. (I added this because while I like to have it open at
the top right of the screen, somone else might prefer bottom-left or
somewhere else.) It will only remember the location if you click Save.

Is it possible to put it on the toolbar?


- It might already be on a toolbar :-)

Because the macro which loads the form is called "EditFind" it should
intercept Word's Find command; this includes when the command is run by
Word's "binoculars" button. If the button with the binoculars icon is not on
any of your toolbars, one way you could add it as follows:

-- Open the template that contains the mini find stuff. (Either open it
through Word's FileOpen dialog, or right-click it in Explorer and choose
Open.)
-- Click ToolsCustomize to open the Customize dialog.
-- Ensure that the template containing the mini find stuff is selected in
the "Make toolbar available to" box.
-- Click the Toolbars tab.
-- Click New.
-- In the Toolbar name box, replace the suggested name with something
meaningful - e.g. My Macros.
-- Click the Commands tab.
-- In the Categories window, click Edit.
-- In the Commands window, scroll down until you can see the Find command
and, using the left mouse button, drag it onto your new toolbar.
-- Drag the new toolbar to where you want it.
-- Close the Customize dialog.
-- Save and close the template.
-- Restart Word. If the template is located in Word's startup folder the new
toolbar should be available.

i must keep pressing enter for each successive search. Is that correct?


- You do need to press Enter for each search (or click Find). I'm not sure
what you would like as an alternative to that. If you're looking for
something which finds all occurrences of the search text in one go, check out
the "Finder" utility at this link:
http://jay-freedman.info/

Regards.

Ed

"Bcfd-IT3" wrote:

Hi Ed,
OK, I tried your macro code and I think I got it right. the things I don't
get a I don't get the "four levels of transparency" that I can cycle
through by double clicking an empty area of the form. I've tried that and
don't get any response. Am I doing something wrong? I'm double clicking
inside the search box, correct?
Next, I don't get the dragging and dropping the search dialog box to my
preferred location. then it will save there next time. it just pops up when
i press ctrl+F each time.
Is it possible to put it on the toolbar? and if so, how do I do that?
when I envoke the ctrl+F or edit\search, i enter the word or words I'm
looking for in the document and press enter to start the search just as you
would in word's search tool (although there are other options i can choose),
but i must keep pressing enter for each successive search. Is that correct?
Just want to make sure i did everything right.
I really would like to put it out on a toolbar so that i can copy this
macro/template to other users computers so they can see that when they start
word up.
Thanks for your help
bcfd-IT3

"Bcfd-IT3" wrote:

Thanks Ed,
I'll give it a try and post back with my results
Bcfd-IT3

"Ed" wrote:

Hi Bcfd-IT3 (& espuma58),

Here is the code for the mini find dialog. The dialog is very basic; its
purpose is just to allow you to perform basic searches in an open document,
keeping the dialog onscreen but unobtrusive. (It doesn't allow you to search
linked docs or anything.)

The EditFind macro intercepts Words Find commands and runs the mini find
dialog instead of Words Find dialog. (So you can use EditFind, Ctrl+F etc.)

It has four levels of transparency which you can cycle through by
double-clicking an empty area of the form. (One issue that I have on my PC
which may be to do with my particular setup is that if I invoke the mini find
dialog using a toolbar button the form remains opaque.)

You can drag the dialog to your preferred location on the screen and click
the Save button and next time it loads it should load to the saved location
and with the saved transparency level.

The textbox on the form should keep the focus after each find so you can
perform several searches without having to keep clicking the textbox.

You can if you want click in the document and work with the document while
keeping the dialog visible.

The Find button has its Default property set to true so you can activate it
by pressing Enter.

The Quit button has its Cancel property set to true so you can close the
form (when it has the focus) by pressing Esc.

The BuiltIn button invokes Words normal Find dialog.

The instructions that follow are for versions of Word from 97 to 2003.

Create a template to hold the VBA stuff as follows:

- Determine the location of Word's startup folder. Go to ToolsOptionsFile
LocationsStartup and click Modify. Sometimes the path is displayed in the
"Folder name" box at the bottom of the dialog, and sometimes you need to
click the "Look in" drop-down at the top of the dialog.

- Create a blank template and save it into the startup folder from the
previous step. For the purposes of these instructions, Im using a template
name of €śMyMacros.dot€ť.

Create the UserForm as follows:

- With MyMacros.dot open, open the Visual Basic Editor (VBE). To do this,
use Alt+F11 or go to ToolsMacroVisual Basic Editor.

- In the VBE, make sure you can see the Project Explorer window. (If
necessary, click ViewProject Explorer.)

- In the Project Explorer, select the MyMacros project.

- With MyMacros selected, click InsertUserForm. A new userform appears
(possibly named €śUserForm1€ť).

- Ensure that you can see the Properties window. (If necessary, click
ViewProperties Window.)

- Click the form to select it and in the Properties window, set the
following properties:
Name: frmFind
Caption: Mini-Find
Height: 78.75
Width: 177

Add the controls as follows:

- Click the form to select it and ensure that you can see the Control
Toolbox. (If necessary, click ViewToolbox.)

- From the Toolbox, drag a textbox onto the form and set these properties:
Name: txtFindText
Left: 6
Top: 6
Height: 18
Width: 162

- From the Toolbox, drag a CommandButton onto the form and set these
properties:
Name: cmdFind
Accelerator: F
Default: True
Left: 6
Top: 30
Height:18
Width: 36

- From the Toolbox, drag a CommandButton onto the form and set these
properties:
Name: cmdBuiltIn
Accelerator: B
Left: 48
Top: 30
Height:18
Width: 36

- From the Toolbox, drag a CommandButton onto the form and set these
properties:
Name: cmdSave
Accelerator: S
Left: 90
Top: 30
Height:18
Width: 36

- From the Toolbox, drag a CommandButton onto the form and set these
properties:
Name: cmdQuit
Accelerator: Q
Cancel: True
Left: 132
Top: 30
Height:18
Width: 36

Add the form code as follows:

- Click the form to select it and then click ViewCode.

- In the code window that opens delete anything thats there, then paste the
form code into the window.

- Add a module for the EditFind macro.

- Click InsertModule.

- In the Project Explorer, select the module thats just been created.

- Ensure that you can see the Properties window (if necessary, click
ViewProperties Window).

- In the Properties window, change the modules name to something meaningful
such as €śmodMain€ť.

- Click in the modules code window and paste the code for the module.

- In the VBE, click the Save icon on the toolbar to save your work.

Close the template and re-start Word..

Test (e.g. by Ctrl+F).

------------------------------------------------------------------
This is the code to be pasted into the forms code window:

Option Explicit

Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000

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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long

Private Sub cmdBuiltIn_Click()
Dialogs(wdDialogEditFind).Show
End Sub

Private Sub cmdFind_Click()
Selection.Find.ClearFormatting

With Selection.Find
.Text = txtFindText.Text
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute

txtFindText.SetFocus
txtFindText.SelStart = 0
txtFindText.SelLength = Len(txtFindText.Text)
End Sub

Private Sub cmdQuit_Click()
Unload Me
End Sub

Private Sub cmdSave_Click()
SaveSetting AppTitle, "Config", "Top", Me.Top
SaveSetting AppTitle, "Config", "Left", Me.Left
SaveSetting AppTitle, "Config", "Opacity", FormOpacity
End Sub

Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Select Case FormOpacity
Case 64
FormOpacity = 128
Case 128
FormOpacity = 182
Case 182
FormOpacity = 255
Case 255
FormOpacity = 64
End Select

SetOpacity
End Sub

Private Sub UserForm_Initialize()
SetOpacity
End Sub

Private Sub SetOpacity()
Dim hWnd As Long
Dim ret As Long

hWnd = FindWindow(vbNullString, Me.Caption)
ret = GetWindowLong(hWnd, GWL_EXSTYLE)
ret = ret Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, ret
ret = SetLayeredWindowAttributes(hWnd, 0, FormOpacity, LWA_ALPHA)

End Sub
------------------------------------------------------------------

------------------------------------------------------------------
This is the code to be pasted into the code module:

Public Const AppTitle As String = "Mini-Find"
Public FormOpacity As Variant

Private hWnd As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Sub EditFind()
Const DefaultFormTop As Integer = 20
Const DefaultFormLeft As Integer = 600
Const DefaultFormOpacity As Integer = 128
Dim MyForm As frmFind
Dim FormTop As Variant
Dim FormLeft As Variant

hWnd = FindWindow("ThunderDFrame", AppTitle)

If hWnd = 0 Then
FormOpacity = GetSetting(AppTitle, "Config", "Opacity")
If FormOpacity = "" Then FormOpacity = DefaultFormOpacity

Set MyForm = New frmFind

FormTop = GetSetting(AppTitle, "Config", "Top")
FormLeft = GetSetting(AppTitle, "Config", "Left")