簡體   English   中英

VBA SAP“未定義用戶定義類型”

[英]VBA SAP "user defined type not defined"

在嘗試使用 Vba 自動化一些 SAP 事務時,我收到錯誤“未定義用戶定義類型”。 我想我的參考文獻中應該有“SAP Gui API”,但我再也找不到它了。 在我重新啟動計算機之前,這曾經有效。 有任何想法嗎?

 Option Explicit
Public SapGuiAuto, WScript, msgcol   
Public Application  As GuiApplication      // I get the error here /// 
Public Connection As GuiConnection
Public session As GuiSession


Sub Processing ()

Dim W_Obj1, W_Obj2, W_Obj3, W_Obj4, iRow
Dim W_Func
Dim W_Src_Ord
Dim W_Ret As Boolean
Dim itemcount As Integer
Dim itemmax As Integer
Dim objSheet As Worksheet
Const startrow As Integer = 7 

Set objSheet = ActiveWorkbook.ActiveSheet


Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
Set Connection = Application.Children(0)
Set session = Connection.Children(0)


If Not IsObject(Application) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = Application.Children(0)
End If
If Not IsObject(session) Then
   Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session, "on"
   WScript.ConnectObject Application, "on"
End If
session.findById("wnd[0]").Maximize
For iRow = startrow To objSheet.UsedRange.Rows.Count
   
// SAP script    
Next   
End Sub

如果您進行以下更改,那么它應該可以工作。

例如:

'Option Explicit
' Public SapGuiAuto, WScript, msgcol   
' Public Application  As GuiApplication      // I get the error here /// 
' Public Connection As GuiConnection
' Public session As GuiSession


Sub Processing ()

Dim W_Obj1, W_Obj2, W_Obj3, W_Obj4, iRow
Dim W_Func
Dim W_Src_Ord
Dim W_Ret As Boolean
Dim itemcount As Integer
Dim itemmax As Integer
Dim objSheet As Worksheet
Const startrow As Integer = 7 

Set objSheet = ActiveWorkbook.ActiveSheet


Set SapGuiAuto = GetObject("SAPGUI")
Set SapApplication = SapGuiAuto.GetScriptingEngine
Set Connection = SapApplication.Children(0)
Set session = Connection.Children(0)

'If Not IsObject(Application) Then
'   Set SapGuiAuto = GetObject("SAPGUI")
'   Set Application = SapGuiAuto.GetScriptingEngine
'End If
'If Not IsObject(Connection) Then
'   Set Connection = Application.Children(0)
'End If
'If Not IsObject(session) Then
'   Set session = Connection.Children(0)
'End If
'If IsObject(WScript) Then
 '  WScript.ConnectObject session, "on"
 '  WScript.ConnectObject Application, "on"
 'End If
session.findById("wnd[0]").Maximize
For iRow = startrow To objSheet.UsedRange.Rows.Count

 // SAP script    
Next   
End Sub

問候, ScriptMan

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM