Assigning macro`s in Word

G

Gunnar

Hi

I have a problem assigning macros to figures and other
things in Word. In Excel is just to right click and you
get an option to assign macro`s.

Is there anything special I need to do?

Thanks in advance.
Gunnar
 
G

Gunnar

I see. I just tried to insert a formfield, but how do I
make my macro appear in the scroll-down list?? There were
10 entries in there but not mine. I made mine in a new
module.
Any comments on that?

Regards
Gunnar
 
C

Chris

I've just been experimenting with Insert | Field
{ MACROBUTTON Test_this asdf }
This is a great little way to invoke a Sub.
However, there seems to be no way to pass arguments.
I'm basically doing something via a .dot that would,
 
M

Marty Lee

Howdy Gunnar,

It seems that you would like to permit the user to
click on a graphic in a Word document and have that action
initiate execution of a macro. Is that correct? I took a
look at that problem a while back and concluded that it
was pretty difficult. My kludge of a solution was to put
an invisible button over the graphic. The user thought
that he was clicking on a graphic, mechanistically he
clicked on the button and that action launched the macro.
I don't remember all the steps, but it was a clumsy
solution. Two problems arose. First, I never figured out
a good way of keeping the button and the graphic exactly
aligned. The user sometimes had to "click around",
especially if the graphic got shifted to a new page. The
second problem arose when experienced users tried to use
standard techniques to resize or move the graphic.
Instead they wound up executing the macro. If you get a
better solution could you post it?

Thanks,
Marty

(my email address is corrupted to avoid junk mail 'bots',
the correct address should read ".msn" rather than "nsm")
 
S

Steve

Hi Marty,

The solution is simple if the audeance is Word 2000 or greater. There is a
click event that you can put code in. Test to see if the selection contains
whatever you want to respond to, if it does do your actions then set the
Cancel parameter to True. Word will stop processing the event. Below is my
code; ignore all the trace code.

'''Handle the double click event
Private Sub AppEvents_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel
As Boolean)

On Error GoTo ErrorHandler
#If Trace = 1 Then
Const Err_Source As String = MODULE_NAME &
":AppEvents_WindowBeforeDoubleClick"
frmTracer.StatusTextAdd "-> " & Err_Source
#End If

Dim bk As Word.Bookmark
Dim shp As Word.InlineShape
Dim fld As Word.Field
Dim rng As Word.Range
Static bolEatOne As Boolean

'''Only allow the editing of the first slide in the selected range.
If Selection.InlineShapes.Count Then
Set shp = Selection.InlineShapes(1)
If Selection.Fields.Count Then
Set fld = Selection.Range.Fields(1)
If fld.Type = wdFieldIncludePicture Then
EditSlide_Selected Selection.Range
Cancel = True
GoTo ExitProc
End If
End If
End If

ExitProc:
#If Trace = 1 Then
frmTracer.StatusTextAdd "<- " & Err_Source
#End If
Exit Sub
ErrorHandler:
#If Trace = 1 Then
frmTracer.StatusTextAdd "(ErrorHandler) " & Err_Source & "; Erl:="
& Erl & "; " & Err.Number & ", " & Err.Description
#End If
Err.Clear
Resume Next
#If Trace = 1 Then
frmTracer.StatusTextAdd "<- " & Err_Source
#End If
End Sub
 
Top