Subject: RE: UI document close
I tried putting that gpprocessole in an agent and it won’t even let me save the agent when I put that in.
not sure why, but it won’t.
I wrote the thing in a HURRY so it doesn’t surprise me if I have stuff in there I don’t need.
Function gpProcessOLEObjectUI2(psCmd$) As String
' This routine is called from the SmartIcons. It is used to create and edit
' OLE obejcts.
Dim bObject As Integer
Dim sCmd$, sReturn$, sTmpFile$
Dim sOleField$, sOleObjProgID$, sOleName$, sOleClass$
' LN Objects
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Dim vOLEObject As Variant
Dim vWord As Variant
Dim vWordBasic As Variant
On Error Goto ipErrorHandler
' Initialization
sOleName$ = ""
sOleClass$ = ""
sReturn$ = ""
bObject% = False
' Get the command to execute
sCmd$ = Trim$(Ucase$(psCmd$))
Print "Doing OLE processing: " & sCmd$
' Initialize LN Objects
Set ws = New NotesUIWorkspace
Set uidoc = ws.CurrentDocument
uidoc.AutoReload = False
Set docTemp = uidoc.Document
' If in preview mode then exit
If (uidoc.InPreviewPane) Then
Exit Function
End If
' Check to see if an OLE field and type are specified on the form. If not, then exit.
If docTemp.hasitem("$OLEObjProgID") Then
bObject% = True
sOleField$ = docTemp.~$OLEObjField(0)
sOleObjProgID$ = docTemp.~$OLEObjProgID(0)
Else
Print "No OLE field is specified on this document."
Exit Function
End If
Select Case sCmd$
Case "NEW"
If bObject% Then
Gosub ipNewObject
End If
Case "EDIT"
If bObject% Then
Gosub ipObjectName
If Len(sOleName$) Then
Gosub ipEditObject
Else
Messagebox "Unable to access embedded object.", 64, "Error"
End If
End If
Case "NEWOREDIT"
' Determine if there is an embedded object. If so, do Edit
' If not, then do New.
If bObject% Then
Gosub ipObjectName
If Len(sOleName$) Then
Gosub ipEditObject
Else
Gosub ipNewObject
End If
End If
Case "NAME"
If bObject% Then
Gosub ipObjectName
End If
sReturn$ = sOleName$
Case "CLASS"
If bObject% Then
Gosub ipObjectClass
End If
sReturn$ = sOleClass$
Case "PRINT"
If bObject% Then
Gosub ipObjectName
Gosub ipPrintObject
Else
Call uidoc.Print
End If
Case "SAVEAS"
If bObject% Then
Gosub ipObjectName
Gosub ipSaveObject
End If
Case Else
End Select
ipFinish:
Print ""
' Deallocate all objects
Set rtitem = Nothing
Set object = Nothing
Set vWordBasic = Nothing
Set vWord = Nothing
gpProcessOLEObjectUI2 = sReturn$
Exit Function
ipNewObject:
' Make sure the document is in edit mode
If uidoc.EditMode = False Then
uidoc.EditMode = True
End If
' Go to the field that will contain the object
uidoc.gotofield(sOleField$)
' Get the name of the new object from the field on the form
sOleName$ = sOleObjProgID$
' Create a new object
Print "Creating a new " & sOleName$ & "..."
Call uidoc.CreateObject(sOleName$, sOleObjProgID$, "")
Return
ipEditObject:
' Make sure the document is in edit mode
If uidoc.EditMode = False Then
uidoc.EditMode = True
End If
' Launch the OLE object
Print "Editting " & sOleName$ & "..."
Set vOLEObject = uidoc.GetObject(sOleName$)
Return
ipPrintObject:
Print "Printing " & sOleName$ & "..."
Select Case Ucase$(sOleName$)
Case "WORD.DOCUMENT", "WORD.DOCUMENT.8"
' Get the handle to the Word object and activate the window
Set vWord = object.Activate ( True )
' Minimize the application
vWord.Application.WindowState = 2
' Get the handle to Word Basic
Set vWordBasic = vWord.Application.WordBasic
' Print the document
vWordBasic.FilePrint
' Close the document
vWordBasic.FileClose
Case Else
Messagebox "Unable to process embedded object named '" & sOleName$ & "'", 64, "Error"
End Select
Return
ipSaveObject:
Print "Saving " & sOleName$ & "..."
Select Case Ucase$(sOleName$)
Case "WORD.DOCUMENT", "WORD.DOCUMENT.8"
' Get a file name
'sTmpFile$ = Inputbox("File Name: ", "Save As", "c:\temp\newdoc.doc")
sTmpFile$="c:\resfiles\doc.doc"
If Len(sTmpFile$) = 0 Then
Return
End If
If gpFileExists(sTmpFile$) Then
Kill sTmpFile$
End If
' Get the handle to the Word object and activate the window
Set vWord = object.Activate ( True )
' Minimize the application
vWord.Application.WindowState = 2
' Get the handle to Word Basic
Set vWordBasic = vWord.Application.WordBasic
' Save the document
vWordBasic.FileSaveAs sTmpFile$
' Close the document
vWordBasic.FileClose
Case Else
Messagebox "Unable to process embedded object named '" & sOleName$ & "'", 64, "Error"
End Select
Return
ipObjectName:
sOleName$ = ""
Set rtitem = docTemp.GetFirstItem(sOleField$)
If rtitem Is Nothing Then
Else
Set object = rtitem.EmbeddedObjects(0)
If object Is Nothing Then
Else
sOleName$ = object.name
End If
End If
Print "Object's name is " & sOleName$
Return
ipObjectClass:
sOleClass$ = ""
Set rtitem = docTemp.GetFirstItem(sOleField$)
If rtitem Is Nothing Then
Else
Set object = rtitem.EmbeddedObjects(0)
If object Is Nothing Then
Else
sOleClass$ = object.class
End If
End If
Print "Object's class is " & sOleClass$
Return
ipErrorHandler:
Call gpError("Error (gpProcessOLEObjectUI2): " & Cstr(Err) & "-" & Error$)
Resume ipFinish
End Function
I didn’t write this script, and I tried putting a uidocument close method line in it but it would give me an error message when i did.