Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Viewing Word documents from VFP
Message
From
21/06/2000 03:35:00
 
 
To
19/06/2000 15:24:13
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00376075
Message ID:
00382569
Views:
67
Sam:

This is a continuation of the previous message. Save everything below as TestWord.bas


Sub SetCommands(tlEnabled As Boolean)

' ======================================
' Loop through the toolbars collection
' and disable unwanted options.
' ======================================

Dim loToolBar As CommandBar

For Each loToolBar In CommandBars
SetToolbarCommands toCommandBar:=loToolBar, tlEnabled:=tlEnabled
Next

End Sub
Sub SetToolbarCommands(toCommandBar As CommandBar, tlEnabled As Boolean)

' ======================================
' Loop through the Controls collection
' and disable unwanted options.
'
' It is necessary to call a similar
' subroutine for submenu because a
' CommandBarControl is not a
' CommandBar.
' ======================================
Dim loControl As CommandBarControl

For Each loControl In toCommandBar.Controls
If loControl.Type = msoControlPopup Then
SetControlPopupCommands toControlPopup:=loControl, tlEnabled:=tlEnabled
Else
If IsUnwantedCommand(loControl.ID) Then
loControl.Enabled = tlEnabled
End If
End If
Next

End Sub
Sub SetControlPopupCommands(toControlPopup As CommandBarControl, tlEnabled As Boolean)

' ---------------------------------
' Disable all unwanted options.
'
' This subroutine calls itself
' recursively to handle submenus.
' ---------------------------------
Dim loControl As CommandBarControl

For Each loControl In toControlPopup.Controls
If loControl.Type = msoControlPopup Then
SetControlPopupCommands toControlPopup:=loControl, tlEnabled:=tlEnabled
Else
If IsUnwantedCommand(loControl.ID) Then
loControl.Enabled = tlEnabled
End If
End If
Next

End Sub
Function IsUnwantedCommand(intCommandID As Integer) As Boolean

' ====================================
' Specifies if an option is disabled
' when editing the Tax Representative
' Narrative.
' ====================================
IsUnwantedCommand = False

Select Case intCommandID
Case 748
'
' Save As
' -------
' Disabled because the calling app expects the document
' to be saved under a filename specified by the
' application.
'
IsUnwantedCommand = True
Case 3147
'
' Save as HTML
' ------------
' Disabled because the calling app expects the document
' to be saved under a filename specified by the
' application.
'
IsUnwantedCommand = True
Case 246
'
' Mail Merge
' ----------
' Disabled because we don't want the user to create a new
' document. This situation would arise if the user elects
' to MailMerge to a new document.
'
IsUnwantedCommand = True
Case 797
'
' Customize
' ---------
' Disabled because the user could drop new unwanted options
' on any toolbar.
'
IsUnwantedCommand = True
End Select

End Function
Sub DocumentAutoNew()

Dim oMenuBar As CommandBar
Dim oControl As Control
Dim oMenuControl As CommandBarControl
Dim oMenuPopup As CommandBarPopup
Dim oMenuItem As CommandBarControl

'
' Disabled unwanted commands
'
SetCommands (False)

'
' Put up an extra menu option. Delete and reset.
'
Set oMenuBar = CommandBars.ActiveMenuBar

For Each oMenuControl In oMenuBar.Controls
If oMenuControl.Caption = "&File" Then
Set oMenuPopup = oMenuControl

' Delete the "Return to VFP" menu item
For Each oMenuItem In oMenuPopup.Controls
If oMenuItem.Caption = "Return to VFP" Then
oMenuItem.Delete
Exit For
End If
Next

' Put up the "Return to VFP" menu item
For Each oMenuItem In oMenuPopup.Controls
If oMenuItem.Caption = "E&xit" Then
Set oNewItem = oMenuControl.Controls. _
Add(Type:=msoControlButton, _
Before:=oMenuItem.Index, _
Temporary:=True _
)
With oNewItem
.Caption = "Return to VFP"
.OnAction = "DocumentAutoClose"
End With
Exit For
End If
Next
End If
Next


End Sub
Sub DocumentAutoClose()

'
' To programmer:
' --------------
' Tou have to supplay the names of
' * the template
' * the calling application
'
' It IS possible to set these at runtime but it is for you
' to discover how...
'

Dim strPrompt As String
Dim strTitle As String
Dim intButtons As Integer
Dim strTemplate As String
Dim strCallingApp As String
Dim loTemplate As Template

strPrompt = "Do you want to save the changes you made to " & _
UCase(ActiveDocument.Name) & "?"
intButtons = vbYesNo + vbExclamation
strTitle = "Microsoft Word"
strTemplate = UCase("TestWord.dot")
strCallingApp = "Microsoft Visual FoxPro"


'
' Save document if necessary
'
If Not Application.ActiveDocument.Saved Then
If MsgBox(strPrompt, intButtons, strTitle) = vbYes Then
Application.ActiveDocument.Save
Else
' Bypass the normal Word prompt and set flag
' to continue forward.
Application.ActiveDocument.Saved = True
End If
End If


'
' Reset disabled commands
'
SetCommands (True)

'
' Trick Word into thinking that the template is saved in
' order not to be prompted "Save TestWord.Dot?" when the
' narrative is closed. This is necessary because the
' template is changed any time the
'
For Each loTemplate In Templates
If UCase(loTemplate.Name) = strTemplate Then
loTemplate.Saved = True
Exit For
End If
Next loTemplate

'
' Activate Calling Application if present.
'
If Application.Tasks.Exists(strCallingApp) Then
Application.Tasks(strCallingApp).WindowState = wdWindowStateMaximize
Application.Tasks(strCallingApp).Activate (True)
End If


End Sub
Sub AutoNew()

DocumentAutoNew

End Sub
Sub AutoOpen()

DocumentAutoNew

End Sub
Sub AutoClose()

DocumentAutoClose

End Sub
Sub AutoExit()

DocumentAutoClose

End Sub
Previous
Reply
Map
View

Click here to load this message in the networking platform