Hi,
My aim is when a user clicks on a macro button in Word, it displays documents of a specific type in the DocOpenDlg. Then they select one document and open it.
The problem is when I do not include this line:
objContextItems.Add "IManExt.OpenCmd.Integration", True
it opens the document but then displays the following error, signifying that the Execute failed:
"One or more documents could not be opened. - Could not launch application to open the document".
However, when I do include that line, which I know I'm supposed to in Word, the document does not open at all.
Sub GetPrecedents()
Dim dms As New ManDMS
Dim sess As IManSession
Dim pSearchParams As IManage.IManProfileSearchParameters
Dim pSearchParam As IManage.IManProfileSearchParameter
Dim commands(0) As String
Dim objExtend As iManO2K.iManageExtensibility
Set objExtend = Application.COMAddIns("IManO2K.AddinForWord2000").Object
If objExtend.CurrentMode = nrConnectedMode Then
'get the dms and session objects
Set dms = objExtend.Context("NRTDMS")
Set sess = dms.Sessions.ItemByName("PIPERDOCS")
'create empty ProfileSearchParameter collection
Set pSearchParams = dms.CreateProfileSearchParameters
'set search parameters
Set pSearchParam = pSearchParams.Add(imProfileAttributeID.imProfileType, "WORD")
Set pSearchParam = pSearchParams.Add(imProfileAttributeID.imProfileClass, "VPS")
' Set properties on dialog object
OpenDocDlg.NRTDMS = dms
OpenDocDlg.SingleSel = True
OpenDocDlg.ShowContainedDocuments = pSearchParams
OpenDocDlg.CloseOnOK = False
OpenDocDlg.FilterAppType = "WORD"
'Define the commands that should appear on the action menu - we just want the open command
commands(0) = "
@0@&Open "
OpenDocDlg.CommandList = commands
'Display the dialog
OpenDocDlg.Show (OpenDocDlg.Window())
Set dms = Nothing
End If
End Sub
Private Sub OpenDocDlg_OnOK(ByVal pMyInterface As Object)
Dim Doc As Variant
'Put documents selected by end-user in an array
Doc = pMyInterface.DocumentList
Select Case pMyInterface.CommandSelected
Case 0
OpenDocument (Doc)
End Select
'pMyInterface = Nothing
End Sub
Private Sub OpenDocument(ByVal Docs As Variant)
On Error GoTo ErrorProcessor
Dim Doc As IManage.NRTDocument
Dim objCommand As IMANEXTLib.OpenCmd
Dim objContextItems As IMANEXTLib.ContextItems
Dim objSelectedDocs(0) As IManage.NRTDocument
Dim i, ct As Long
ct = UBound(Docs) - LBound(Docs)
For i = 0 To ct
Set Doc = Docs(i)
Set objSelectedDocs(0) = Doc
'Create command and contextitems objects
Set objCommand = New IMANEXTLib.OpenCmd
Set objContextItems = New IMANEXTLib.ContextItems
objContextItems.Add "SelectedNRTDocuments", objSelectedDocs 'pass the selected document
objContextItems.Add "IManExt.OpenCmd.NoCmdUI", True 'don't display error msgs if any errors occur
objContextItems.Add "IManExt.OpenCmd.Integration", True 'indicate you're in an instance of Office Integrated app
' Initialize the command with populated ContextItems collection
objCommand.Initialize objContextItems
' Use the Update method to find out if the command is available,
' based on the information posted to the ContextItems collection
objCommand.Update
' If the command is active, it can be executed.
If objCommand.Status = (objCommand.Status And IMANEXTLib.CommandStatus.nrActiveCommand) Then
objCommand.Execute
Dim bRefresh As Boolean
bRefresh = objContextItems.Item("IManExt.Refresh")
If bRefresh = True Then
Dim pImportedDoc As IManage.NRTDocument
Set pImportedDoc = objContextItems.Item("ImportedDocument")
If Not pImportedDoc Is Nothing Then
' When finished using the ContextItems, remove them from the collection.
objContextItems.Remove ("IManExt.Refresh")
objContextItems.Remove ("ImportedDocument")
End If
End If
End If
Next i
' Free pointers before exiting
Set objCommand = Nothing
Set objContextItems = Nothing
Set Doc = Nothing
ErrorProcessor:
MsgBox ("Document opening error")
End Sub