General information
Category:
COM/DCOM and OLE Automation
John:
This is the strategy I adopeted in sevral applications. hOPE IT HELPS YOU.
*****
First save your master as a Word template (.dot) and then add a ReturnToXXX macro to it, where XXX is the name of your application. Add a call to ReturnToXXX macro in the AutoClose and AutoExit macros.
Sub ReturnToXXX()
Dim lcPrompt As String
Dim lcTitle As String
Dim lnButtons As Integer
lcPrompt = "Do you want to save the changes you made to " & Appplication.ActiveDocument.Name & "?"
lnButtons = vbYesNo + vbExclamation
lcTitle = "Microsoft Word"
'
' Save document if necessary
'
If Not Application.ActiveDocument.Saved Then
If MsgBox(lcPrompt, lnButtons, lcTitle) = vbYes Then
' Save document
Application.ActiveDocument.Save
Else
' Bypass the normal Word prompt and set flag
' to continue forward.
Application.ActiveDocument.Saved = True
End If
End If
'
' Reset menu options
'
' Write a macro to enable the menu options if necessary.
' This is usually not required in most cases.
'
' Trick Word into thinking that the template is saved in
' order not to be prompted "Save XXX.Dot?" when the
' document is closed.
'
' This is necessary because the template is changed any
' time the user makes some type of formatting change.
'
For Each loTemplate In Templates
If UCase(loTemplate.Name) = "THENAMEOFYOURTEMPLATE.DOT" Then
loTemplate.Saved = True
End If
Next loTemplate
'
' Activate XXX if present.
'
If Application.Tasks.Exists("XXX") Then
Application.Tasks("XXX").WindowState = wdWindowStateMaximize
Application.Tasks("XXX").Activate (True)
End If
End Sub
*****
Second, write a function (method) in VFP preventing your form (or appliaction from closing if a specified document is still open).
*****
Last, do this in your ... Do some stuff:
1). Open your Word templates.
2). Save it under a specified name (the same name that will prevent your form/application from closing).
3). Put text into bookmarks.
4). Save document (do not changhe its name).
5). Disable unwanted Word options. Depending on what exactly you are trying to do, you may want to consider disabling the following options (Control.ID, Description):
18 : New (the File menu command)
2520 : New (the tool)
23 : Open
106 : Close
748 : SaveAs
246 : MailMerge
752 : Exit
797 : Customize
I usually disable SaveAs because I don't want the document to be renamed.
6.) Activate Word to give the user a chance to modify the document.
I have used this strategy with success in several applications.
Daniel
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only