Q: SaveAs?

K

Klaus H

I have an document cotaining an UserForm.
How do i make the document to save as the same filename, but in two
different libraries, om closing document?
The next time i open one of these documents, i don't want them to save
again.

Klaus H
 
P

Perry

Hmm, requires a couple of steps:

1) mechanism to identify whether documents are already saved (in 2
locations)
- one option is to check in the alternate location whether a document with
same name is already present (or not)
- another mechanism is to create a custom document property in the template
, for instance DocSaved with a default FALSE value.
Before saving the doc, you could toggle this value to TRUE and respond
accordingly when the document gets opened later ...

2) there's no BeforeSave event you can use in the normal Word
document/template coding interface to respond to and intercept Save actions;
you'll have to raise the event handler to the Application level in order to
expose the event.
http://msdn2.microsoft.com/en-us/library/aa165072(office.10).aspx
See example code sequence, below

3) Next question will be: where am I going implement the Application Event
handling mechanism?
Do you have an addin, in which you can host the solution?

4) As part of item 3, you'll have to think about the scope of the
application event handling mechanism.
If you implement such an Application Event Handling mechanism in an addin,
you'll have to realise that
it will affect all documents passed through the instance of Word hosting the
Application Event Handling solution.

5) Last:
I'm not saying it's impossible, it's doable alright ...
....but you have to make some decisions, as you'll probably have noticed.

--
Krgrds,
Perry

=== Sample in a classmodule's codegrid:
Public WithEvents app As Word.Application

Private Sub app_DocumentBeforeClose( _
ByVal Doc As Document, _
Cancel As Boolean)

'your action when closing a document;
'note: 1st param is target document being closed
'2nd param system callback to bailout of the event
End Sub

Private Sub app_DocumentBeforeSave( _
ByVal Doc As Document, _
SaveAsUI As Boolean, _
Cancel As Boolean)

'your action when closing a document;
'note: 1st param is target document being saved
'2nd param type of Save action (Save/SaveAs)
'3rd param system callback to bail out of the event
End Sub

Private Sub app_DocumentOpen(ByVal Doc As Document)
'your action when opening a document;
'note parameter
End Sub

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

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