Detecting if Word is starting by double-clicking a doc file

S

stephenc

I use an autoexec macro in Word to set up varius things. Part of it opens the
last-opened document (this functionality is enabled/disabled via an INI
setting not shown here):

<snip>
If RecentFiles.Count > 0 Then
RecentFiles(1).Open
End If
<snip>

This works well but I do not want this bit to run if Word is being started
by the user double-clicking on a document file in Explorer (or desktop or
where ever). In this scenario I guess that the document path/filename is in
the Word startup command line.

So my question is this: Is it possible for the autoexec macro to check if
Word is starting with a document in the command line?
 
H

Helmut Weber

Hi Stephen,

how about this one:

Sub autoexec()
Application.OnTime _
When:=Now + TimeValue("00:00:02"), _
Name:="TellmeWhat"
End Sub

Sub TellmeWhat()
If InStr(ActiveDocument.FullName, "\") Then
MsgBox "Word was started with doc"
Else
MsgBox "Word was not started with doc"
End If
End Sub

The decisive point is how long you are waiting,
before starting "TellmeWhat".
You may have to change the value.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

stephenc

Hi Helmut,
I tried out a few times but 2 seconds seems to work fine for me. Thanks for
helping out.
Regards,
Stephenc
 

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