Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2014, 03:21 PM
dherr dherr is offline How to start a Userform when Word is started Windows 8 How to start a Userform when Word is started Office 2007
Advanced Beginner
How to start a Userform when Word is started
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default How to start a Userform when Word is started

Hi,


I tried some versions to start my Userform when Word starts.
When you start word, a new document opens and shows.
I tried to do:
Private Sub Document_New()
myForm.Show
End Sub
This works, when I start a new document and Word is open already, but works not when I start Word with this automatically created new document.
Which code starts the Userform in unison with Word itself?

Regards
Dietrich
Reply With Quote
  #2  
Old 12-14-2014, 03:34 PM
Charles Kenyon Charles Kenyon is offline How to start a Userform when Word is started Windows 7 64bit How to start a Userform when Word is started Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,453
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You might try adding the following code to your Normal.dotm. I usually keep such macros in a module called modAuto.

Code:
Public Sub AutoExec()
myForm.show
End Sub
The thing is that Word creates the document before it gets to your code. I am not sure whether or not that will be the case here as well but suspect it will work. This is supposed to run when Normal.dotm is loaded which is a separate event from the creation of the new document.
Reply With Quote
  #3  
Old 12-14-2014, 03:47 PM
dherr dherr is offline How to start a Userform when Word is started Windows 8 How to start a Userform when Word is started Office 2007
Advanced Beginner
How to start a Userform when Word is started
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Thanks for the fast answer!
The code you show me, I have set this accurate into the module of normal.dotm. But it doesn't work.
I get the error message:
Runtime error. 4248
This order is not available, because no document is open.
What's to do?
Greetings-
Dietrich
Reply With Quote
  #4  
Old 12-14-2014, 04:30 PM
Charles Kenyon Charles Kenyon is offline How to start a Userform when Word is started Windows 7 64bit How to start a Userform when Word is started Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,453
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

My understanding is that it is best to create a new form rather than show the basic one. I believe this is a method of saving memory.

Code:
Sub StartUserForm()
    Dim myNewForm As myForm
    Set myNewForm = New myForm
    myNewForm.Show
    Unload myNewForm
    Set myNewForm = Nothing
End Sub
Reply With Quote
  #5  
Old 12-14-2014, 04:39 PM
Charles Kenyon Charles Kenyon is offline How to start a Userform when Word is started Windows 7 64bit How to start a Userform when Word is started Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,453
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by dherr View Post
Thanks for the fast answer!
The code you show me, I have set this accurate into the module of normal.dotm. But it doesn't work.
I get the error message:
Runtime error. 4248
This order is not available, because no document is open.
What's to do?
Greetings-
Dietrich
Here is code to delay the execution of a macro for a given number of seconds.

Code:
Private Sub HaveABreak(iSeconds As Integer)
'
 ' Macro pauses running of procedure for given number of seconds
' Astrid Zeeland
' https://wordmvp.com/FAQs/MacrosVBA/ShowAllClippitAnimations.htm

 '
Dim lPauseTime As Long
Dim lStart As Long
  lPauseTime = iSeconds
  lStart = Timer 'get current time
  Do While Timer < lStart + lPauseTime
    DoEvents
  Loop
End Sub
Put this into the same module that would hold the AutoExec.

You would call it with HaveABreak (i) where i is the number of seconds you need to wait. Try it with 1. Insert the following into the AutoExec macro before the Show command:

HaveABreak(1)

Last edited by Charles Kenyon; 01-28-2023 at 10:11 AM.
Reply With Quote
  #6  
Old 12-14-2014, 04:53 PM
dherr dherr is offline How to start a Userform when Word is started Windows 8 How to start a Userform when Word is started Office 2007
Advanced Beginner
How to start a Userform when Word is started
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Thank you very much for the ideas!
I will try it tomorrow and send you a feedback.
Reply With Quote
  #7  
Old 12-14-2014, 10:37 PM
gmayor's Avatar
gmayor gmayor is offline How to start a Userform when Word is started Windows 7 64bit How to start a Userform when Word is started Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Code:
Public Sub AutoExec()
myForm.show 
End Sub
will work to display a userform when Word starts, the problem is not the macro, but the userform, which undoubtedly contains code that relates to the non-existent active document, hence the error.

What is it that the userform is supposed to achieve when Word is started.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #8  
Old 12-15-2014, 03:16 AM
dherr dherr is offline How to start a Userform when Word is started Windows 8 How to start a Userform when Word is started Office 2007
Advanced Beginner
How to start a Userform when Word is started
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Hi Graham,
your idea was the right one.
I had in the UserForm_initialize this code: Set oDoc = ActiveDocument.
Now I have changed the programm into:
Delete this line of code but insert
Private Sub UserForm_Activate()
If oDoc Is Nothing Then Set oDoc = ActiveDocument
End Sub

Now all is working! Thank you and have a nice Christmas!
Dietrich (from Salzburg)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start a Userform when Word is started Getting started... Annby Project 3 11-06-2014 03:38 PM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM
How to start a Userform when Word is started Is it possible to take an input from a UserForm in one document to a UserForm in a do BoringDavid Word VBA 5 05-09-2014 09:08 AM
How to start a Userform when Word is started Page footers have started ravl13 Word 3 11-21-2013 12:31 PM
Need Help Getting Started, Please. Thanks ChunkyZergling Outlook 1 04-24-2009 07:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:59 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft