Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
steve - 07 Nov 2007 15:11 GMT
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.
Doug Robbins - Word MVP - 07 Nov 2007 19:29 GMT
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.

Signature

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

>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.
[quoted text clipped - 23 lines]
>
> Thanks.
steve - 07 Nov 2007 21:28 GMT
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.
Shauna Kelly - 09 Nov 2007 09:24 GMT
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

> 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
[quoted text clipped - 23 lines]
>
> Thanks.
fumei - 11 Nov 2007 06:36 GMT
Good advice/question Shauna.  It helps to know what is actually
happening/required.
steve - 11 Nov 2007 19:30 GMT
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
Doug Robbins - Word MVP - 11 Nov 2007 22:48 GMT
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.

Signature

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

> In our organization we are often finding documents in the physical
> files and wondering where the software version is. So what we want to
[quoted text clipped - 22 lines]
>
> Regards
steve - 12 Nov 2007 16:19 GMT
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
Doug Robbins - Word MVP - 12 Nov 2007 19:40 GMT
Perhaps I should have said "create a NEW template...."  The NEW was implied.

Signature

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

> Thank you for your advice.
>
[quoted text clipped - 5 lines]
>
> Regards
steve - 12 Nov 2007 20:12 GMT
Great.

thank you.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.