Open a userform when word opens and on New documents??

S

steve

I have a Userform that I want to open when either a new document is
created or word opens for the first time eg. Document1.

I have tried in VB "ThisDocument/Document_New option and AutoNew
option, but both seem to only work when you already have word open and
create a second document. They dont seem to work when word opens on
the first Document that word opens.

Can anyone provide me with an answer to this.

ALSO

Can anyone provide me with a little insight as far as UserForms. Is it
true that the userform stays open untill you literally tell it to go
away. eg. with unload userform or userform.hide. It seems I have to
add it to the end of each of the buttons code, to get the userform to
go away. FINALY, if this is so, which is best? Unload userform or
Userform.hide . The userform I have pop up simply asks three
questions.
1. No Filename in Document
2. Filename in document
3. Filename and path in document.

You click it,it does the instruction and then exits the code. By the
way this is word97.

Thanks.
 
D

Doug Robbins - Word MVP

Put the code to show the userform in a macro named autoexec() that you
create in the normal.dot template (or a global template which is one that is
stored in the Word Startup folder. If you do not want the form to be
displayed on some occasions, hold down the Shift key when starting Word.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

steve

Thank you for your response. You have provided me with the right
solution but It looks like my code needs a little tweaking which I
dont know how to do. Perhaps you/somone can suggest something.

Heres the problem.

I added the autoexec
Sub Autoexec()
FilenameInFooter.Show
End Sub

This now works fine when I start Word the userform opens nicely.
However, the purpose of the code is to add a footer to the Document1,
based on the users pressing a button. It appears that the autoexec
runs before the first document1 is loading and so, when I press the
button that says add a footer, it gives an error because it cant put a
footer into a document that is not open yet.
It gets stuck on the very first line of the macro that I created.

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If

Any thoughts how I can make the program wait until the new document is
open then run the code.

Thanks.
 
S

Shauna Kelly

Hi Steve

Could we back up here about 6 steps and start again?

Can you describe the business need rather than the technical solution? That
is, if you were in a meeting with senior management, how would you describe
what your tool will do?

Then we'll be able to give you some advice on how to achieve your aim.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
F

fumei via OfficeKB.com

Good advice/question Shauna. It helps to know what is actually
happening/required.
 
S

steve

In our organization we are often finding documents in the physical
files and wondering where the software version is. So what we want to
do is simply put the filename at the bottom of documents that are
created (from now on). Many of the users are not power users, that is
the time and marginal complexity of putting a footer in a document and
then putting the filename is either to much for them, or they are too
lazy to do it. Frankly how many times have I not done it only to hate
myself for not doing it. So we want to have a pop up box that asks
when they start word or create a new document if they want to put the
filename in the footer. They can click no or yes or full name and
path.

I have read on the news groups and it appears that putting the footer
directly in the template is bad. (normal.dot) that is because it
screws up some programs eg if your making labels. So I want to give
people the option of whether they want it or not.

By the way I have subsequetly learned about the "on time " And have
used it to get the autoexec to work the way I want it to.

Thats basically the problem. Dont you'all have users and problems like
that? How do you deal with it other than, searching or telling your
users you lost it you find it. (Im in the IT dept so I dont have that
luxury if I like my job :).

Regards
 
D

Doug Robbins - Word MVP

I would really suggest that you create a template that already contains the
field to return the path and filename in the footer.

Otherwise, create a macro named AutoNew() that contains the following code:

Dim Msg, Style, Title, Response, MyString
Msg = "Do you want to include the file and pathname in the footer of the
document?" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "File and Pathname" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
With ActiveDocument
.Fields.Add
Range:=.Sections(1).Footers(wdHeaderFooterPrimary).Range, _
Type:=wdFieldFileName, Text:="\p"
End With
End If

Probably best if that is created in a template that you save in the Word
Startup folder so that it is loaded as an addin.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

steve

Thank you for your advice.

I was told by others that putting the footer in the template by
default was bad. This was because programs that may expect nothing in
the footer, like makeing a sheet of labels etc can screw up. Have you
heard of this? Would this be a reason not to put it into the footer of
the default normal.dot template.

Regards
 
D

Doug Robbins - Word MVP

Perhaps I should have said "create a NEW template...." The NEW was implied.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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