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 / March 2006

Tip: Looking for answers? Try searching our database.

Code to check the name of the current document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Darryl - 30 Mar 2006 22:48 GMT
Greetings,
I am running Word 2000.   I have a macro that runs when the document is
opened.
It displays a msgbox.  I would like to put a check in to see if the name of
the current
document matches a given string.

ie,
if currentdocument.name eq 'z:\documentstore\mydoc.doc' then
 msgbox "Please use SAVE AS to rename this document before typing in this
form", , "SAVE AS"

what is the appropriate syntax to achieve this ?

thanks,
D
Greg - 31 Mar 2006 02:26 GMT
D,

Something along this line:

Sub AutoOpen()
Dim pString As String
pString = "What ever the name is"
If ActiveDocument.FullName = pString Then
 MsgBox "Whatever message you want"
End If
End Sub
Shauna Kelly - 31 Mar 2006 10:28 GMT
Hi Darryl

Let's try to solve the real problem, rather than the symptom.

It sounds like you're creating a form for people to fill in. And you don't
want them to type in the original form. Instead, you want them to create a
new document for themselves (and you want them to do this using File > Save
As), and type in that document.

Is that the story?

If so, you may be better off turning your document into a template. To do
that, open your document and do File > Save As and save it as a template.
Store the template somewhere that everyone can access, and mark it read
only.

If you put it in the folder identified at Tools > Options > File Locations >
User Templates *or* > Workgroup Templates, then the user can do File > New
and choose your form. Word will automatically create a new document from
your template, and the user can save it as they choose.

If you put it somewhere else, then the user can use Windows Explorer and
double-click the file name to create a new document from the template. Or,
put a shortcut to the template on your desktop.

Hope this helps.

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

> Greetings,
> I am running Word 2000.   I have a macro that runs when the document is
[quoted text clipped - 13 lines]
> thanks,
> D
 
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.