On Open Macro

C

Claudine

Hi,

Does anyone know how I can create a little macro or popup
box that instructs the user on how to use the template?
Just a few lines of text would be included.

Thanks!

Claudine
 
J

Jonathan West

Claudine said:
Hi,

Does anyone know how I can create a little macro or popup
box that instructs the user on how to use the template?
Just a few lines of text would be included.

Try this

Sub SmallPopup()
MsgBox "This is a small message box that tells you how to" _
& vbCr & "use the template. This is the second line of the" _
& vbCr & "instructions. You can include a maximum of 256" _
& vbCr & "characters into a message box like this."
End Sub
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Claudine > écrivait :
In this message, < Claudine > wrote:

|| Hi,
||
|| Does anyone know how I can create a little macro or popup
|| box that instructs the user on how to use the template?
|| Just a few lines of text would be included.
||

From the VBA editor, locate your template name in the project pane on the
left. Then, in the tree structure under you template, fin the module called
"ThisDocument". Double click on that to access its code window. Once there,
use the dropdown list at the top of the code window, the one on the left
(the one that says General). Select Document in that list. Once you do that,
the following Sub will be added automatically in the code window:
'_______________________________________
Private Sub Document_New()

End Sub
'_______________________________________

Now, you have to decide. Do you want your instructions to appear only the
first time the use creates a document from your template? Or every single
time they open their document.

In the first case, just add your code in the Document_New sub. If the
latter, go to the dropdown list on the RIGHT, and select Open, the following
code will be added:
'_______________________________________
Private Sub Document_Open()

End Sub
'_______________________________________

If you need your code to be executed by both subs, create your own third sub
below those two, like
'_______________________________________
Private Sub MySub()

'Your code

End Sub
'_______________________________________

and use:
'_______________________________________
Private Sub Document_New()

MySub

End Sub

'_______________________________________

'_______________________________________
Private Sub Document_Open()

MySub

End Sub
'_______________________________________

This way your code will be executed both when the user creates and opens he
document.

Finally, for your instructions, the easiest is to use MsgBox, like:
'_______________________________________
Sub DisplayInstructions()

Dim MyInstructions As String
Dim MyInstructionsTitle As String

MyInstructions = "When using this template you have to know the following: "
_
& vbCrLf & "First, always regularly save your work. I cannot be held " _
& "responsible for your forgetfulness." & vbCrLf _
& "Second, use the toolbar to insert the autotexts." & vbCrLf & vbCrLf _
& "See how underscores are used to break continuous command lines " _
& "on several lines. Just make sure you enclose the string with quotes "
_
& "on one line, do not forget the spaces to space out the word at the "
_
& "end of a line and the following one on the next line. Then, type a "
_
& "space after the closing quote, followed by the underscore. Hit
""Enter"". " _
& "Type an ampersand (""&"") at the beginning of the following line,
then a " _
& "space followed by the opening quote for that line. And so on." _
& vbCrLf & vbCrLf & "Also, you can use ""vbCrLf"" to insert line
breaks."
MyInstructionsTitle = "Using the template"

MsgBox MyInstructions, vbInformation, MyInstructionsTitle

End Sub
'_______________________________________

Of course, this is a little extreme! Normally, for this much text, I would
use a userform... But, a message box will work just as well.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Jonathan West > écrivait :
In this message, < Jonathan West > wrote:

|| ||| Hi,
|||
||| Does anyone know how I can create a little macro or popup
||| box that instructs the user on how to use the template?
||| Just a few lines of text would be included.
|||
||
|| Try this
||
|| Sub SmallPopup()
|| MsgBox "This is a small message box that tells you how to" _
|| & vbCr & "use the template. This is the second line of the" _
|| & vbCr & "instructions. You can include a maximum of 256" _
|| & vbCr & "characters into a message box like this."
|| End Sub

Just curious Jonathan,

The limit of 256, is it if you use a structure like the one you suggest, or
does it also apply if I declare a string variable to hold the text?
See my suggestion in the same thread. I have over 700 characters (including
spaces).

Or is the limit version related? Has it been increased in Word XP?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

Jean-Guy Marcil said:
Bonjour,

Dans son message, < Jonathan West > écrivait :
In this message, < Jonathan West > wrote:

|| ||| Hi,
|||
||| Does anyone know how I can create a little macro or popup
||| box that instructs the user on how to use the template?
||| Just a few lines of text would be included.
|||
||
|| Try this
||
|| Sub SmallPopup()
|| MsgBox "This is a small message box that tells you how to" _
|| & vbCr & "use the template. This is the second line of the" _
|| & vbCr & "instructions. You can include a maximum of 256" _
|| & vbCr & "characters into a message box like this."
|| End Sub

Just curious Jonathan,

The limit of 256, is it if you use a structure like the one you suggest, or
does it also apply if I declare a string variable to hold the text?
See my suggestion in the same thread. I have over 700 characters (including
spaces).

Or is the limit version related? Has it been increased in Word XP?

Forget the limit of 256 - minor brainstorm on my part, resulting from a
program I was working on recently that was displaying document properties in
message boxes...
 

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