Help: How to call a macro from a field

P

Palhinha

H
Is there a field that results in a Call to a VBA Macro
I waht to have a field hose result-text is calculated from a Macro
Eg, in the Macro code
Public Function TheTime() As Strin
TheTime = No
End Functio

In the Word Text, something like
This was updated at {Some-Command TheTime

Please, reply by eMail to
TI
(e-mail address removed)
 
J

Jay Freedman

Hi Palhinha

A MacroButton field can call a macro. In turn, the macro can change the
string displayed by the MacroButton field. Try this... Insert this macro in
the document or template:

Sub TheTime()
If Selection.Fields.Count > 0 Then
Selection.Fields(1).Code.Text = _
"Macrobutton TheTime " & _
Format(Now, "h:mm:ss am/pm")
End If
End Sub

Put this field in the document and update it:

This was updated at { MacroButton TheTime -undefined- }

Now double-click the field. Wait a few seconds and double-click it again...
and again...
 
P

Palhinha

Hi Freedman
I've seen the tip's in http://word.mvps.org/FAQs, about {AddIn} and {Private} for parameters.
Is there another way?

So that i dont have
1- "DisplayText cannot span more then one line" in a table cell, but wrap
2- Badly "Justifieed Text" when the macro return's to mucho text in a midle of a paragraf.

The idea is to use the macro to get content from a Database, in a difrent way than mail-merge

Thanks again,
Palhinha
 
J

Jay Freedman

Hi Palhinha

This issue is quite different from the time field you asked about before.

There's no way to place display text into a MacroButton field and have it
display on more than one line. (I don't know why, but it's been that way
since at least Word 6.0 and maybe earlier.) In a table you'll always get the
error message if it doesn't fit in the column width, and in regular text the
whole thing will always go to the next line, assuming it all fits on one
line.

The only alternative I can think of is to have the macro put the text before
or after the MacroButton field or completely replace the field, so that
there is only plain text. That means you won't be able to use the field to
run the macro a second time.

In a table, maybe you could have the MacroButtons in one column, and have
the macro put the resulting text into another column in the same row.
 
W

Word Heretic

G'day "Palhinha" <[email protected]>,

The MACROBUTTON field.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Palhinha reckoned:
 

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