"-Begin-----------------------------------------------------------------
Report zGetObejct.
"-Type pools--------------------------------------------------------
Type-Pools OLE2.
"-Variables---------------------------------------------------------
Data App Type OLE2_OBJECT.
Data GetApp Type OLE2_OBJECT.
"-Main--------------------------------------------------------------
Create Object App 'Excel.Application'.
If sy-subrc = 0.
PerForm GetObject Using 'Excel.Application' Changing GetApp.
"-------------------------------------------------------------
"-
"- Now you can use GetApp or App
"- If an object of Excel already exists, it is not
"- necessary to call Create Object
"-
"-------------------------------------------------------------
Free Object App.
EndIf.
"-End-------------------------------------------------------------------
"-SubRoutines begin-----------------------------------------------------
"-GetObject-----------------------------------------------------------
Form GetObject Using ClassName Type String
Changing Result Type OBJ_RECORD.
"-Constants-------------------------------------------------------
Constants CrLf(2) Type c Value %_CR_LF.
"-Variables-------------------------------------------------------
Data ScriptCtrl Type OBJ_RECORD.
Data Expression Type String Value ''.
Data Module Type String Value ''.
"-Macros----------------------------------------------------------
Define AddLine.
Concatenate Module &1 CrLf Into Module.
End-Of-Definition.
AddLine 'Function GetObj(ClassName)'.
AddLIne ' Dim oObj'.
AddLine ' Set oObj = GetObject(, ClassName)'.
AddLine ' If IsObject(oObj) Then'.
AddLine ' Set GetObj = oObj'.
AddLine ' End If'.
AddLine 'End Function'.
Concatenate 'GetObj("' ClassName '")' Into Expression.
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
If sy-subrc = 0.
Set Property Of ScriptCtrl 'AllowUI' = 1.
Set Property Of ScriptCtrl 'Language' = 'VBScript'.
Call Method Of ScriptCtrl 'AddCode' Exporting #1 = Module.
If sy-subrc = 0.
Call Method Of ScriptCtrl 'Eval' = Result
Exporting #1 = Expression.
EndIf.
EndIf.
Free Object ScriptCtrl.
EndForm.
"-Subroutines end-------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |