autoclose/autosave??

G

Guest

I have some code set for closing out of a word doc. The
code itself works fine, but I would like to use it on
either the save/save as or close events. Currently I
have it set up under an "autoclose" module. It works
fine if the user is closing the doc (obviously)...
however, most users will likely try using the "save" menu
option. Here is what I currently have:

Sub autoclose()

'defines variable for filename
Dim strFileNM As String
strFileNM = ActiveDocument.Variables("SOPName").Value

'changes directory default to SOP folder
ChangeFileOpenDirectory _
"C:\Documents and Settings\Owner\My Documents\SOPs\"

'sets filename to value in "SOPName" bookmark & saves as
word doc
'ActiveDocument.SaveAs FileName:=strFileNM,
fileformat:=wdWordDocument
With Dialogs(wdDialogFileSummaryInfo)
.Title = strFileNM
.Execute
End With
End Sub

Thanks!
 
M

Malcolm Smith

Hi

Do you mean that you want to trap the FileSave, FileSaveAs events as well?
Have a couple of routines in your template with those names and they
ought to trap these Word events.

I think that you may also need FileSaveDefault; but I will have to look
(it's half past five in the morning for some odd reason and I am up
without espresso so if I sound a little ragged then you know why!)

Now in your code I would like to ask why you are changing the file
location when you could be doing something like:


Dim strFileNM As String

strFileNM = ActiveDocument.Variables("SOPName").Value
if len(strFileNM) > 0 then
ActiveDocument.SaveAs "C:\Documents and Settings\Owner\My
Documents\SOPs\" & strFileNM
else

end if


You may want to consider some defensive programming in case there is
nothing in the SOPName variable (this is something which I have never used
in this manner) or, in fact, check that this variable exists.

Hope that this helps
- Malc
www.dragondrop.com
 
M

Malcolm Smith

JB

It was half five in the morning, I couldn't sleep as the fox was screaming
outside all night so I was having trouble thinking. But, I am sure that
I got the message across.

More, or even less.

Cheers
Malc
 

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