执行SAP RFC的VBA程序可在Excel 2016本地部署中运行,但不能在Office 365中运行(运行时错误20080008 ...错误的变量类型) [英] VBA program executing SAP RFCs works in Excel 2016 on-prem, but not in Office 365 (Run-time error 20080008...Bad Variant Type)

查看:273
本文介绍了执行SAP RFC的VBA程序可在Excel 2016本地部署中运行,但不能在Office 365中运行(运行时错误20080008 ...错误的变量类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说我看到提到此问题的其他两个线程此处,但它们并没有帮助我可以解决我的问题.

Let me first say that I saw the other two threads that mentioned this issue here and here, but they didn't help me solve my problem.

我已经在本地Excel 2016环境(32位)中测试程序几个星期了,没有任何问题.我的公司即将迁移到Office 365,因此我决定也在那里进行测试.在该系统上,我在 Functions.Connection = objConnection

I've been testing a program for several weeks in the on-prem Excel 2016 environment (32-bit) with no problems. My company is making the move to Office 365 soon, so I decided to test it over there as well. On that system, I'm getting a run-time error on the line Functions.Connection = objConnection

Option Explicit
Public Functions As SAPFunctionsOCX.SAPFunctions
Private LogonControl As SAPLogonCtrl.SAPLogonControl
Private objConnection As SAPLogonCtrl.Connection
Public Func As SAPFunctionsOCX.Function
Public Commit As SAPFunctionsOCX.Function
Public TableFactory As SAPTableFactory
Public silentLogon As Boolean
Public tblReadTableOptions, tblReadTableFields, tblReadTableData As SAPTableFactoryCtrl.Table

Sub ExtractProjectData()
    If objConnection Is Nothing Then LogonToSAP
    InitiateSAPVariables
    Set Func = Functions.Add("BBP_RFC_READ_TABLE")
    Set tblReadTableOptions = Func.Tables("OPTIONS")
    Set tblReadTableFields = Func.Tables("FIELDS")
    Set tblReadTableData = Func.Tables("DATA")

    'extract/transform data from SAP tables

End Sub

Function InitiateSAPVariables()
    Set Functions = Nothing
    Set TableFactory = Nothing
    Set Func = Nothing
    Set Functions = CreateObject("SAP.Functions")
    Set TableFactory = CreateObject("SAP.TableFactory.1")
    Functions.Connection = objConnection 'run-time error here in Office 365 but not in on-prem
End Function

Function LogonToSAP()
    Dim establishConnection As Boolean
    silentLogon = false
    Set LogonControl = CreateObject("SAP.LogonControl.1")
    Set objConnection = LogonControl.NewConnection
    objConnection.Client = "###"
    objConnection.Language = "EN"
    objConnection.SystemNumber = "##"
    objConnection.User = ""
    objConnection.Password = ""
    objConnection.HostName = "###############"
    objConnection.System = "###"
    objConnection.ApplicationServer = "###.###.#.##"
    establishConnection = objConnection.Logon(0, silentLogon)
End Function

快速检查objConnection会告诉我登录成功...因此我知道该部件正在365上工作.由于某种原因,它不喜欢为该对象分配 Connection 属性365环境中的 Functions SAPFunctionsOCX.SAPFunctions对象(请随时纠正我的说法,我知道这不太正确).

A quick check of objConnection tells me that logon was successful...so I know that part is working on 365. For some reason though, it doesn't like assigning the Connection property of the Functions SAPFunctionsOCX.SAPFunctions object in the 365 environment (please feel free to correct my verbiage on that...I know it's not quite right).

请注意,在这两种环境下,我都没有看到任何参考问题,也没有遇到任何编译错误.出现问题的第一个迹象是执行 Functions.Connection = objConnection

Note that I'm not seeing any reference issues nor am I getting any compile errors in either environment. The first sign of trouble is on execution of Functions.Connection = objConnection

这里还有一个问题,那就是我还有另一个较旧的VBA程序,该程序登录到SAP并运行不使用SAPFunctionsOCX.SAPFunctions的远程函数调用,而是将变量R3声明为 Public R3 As Object ,然后稍后在登录代码中将R3设置为 Set R3 = CreateObject("SAP.Functions") ...它不使用OCX.换句话说,旧例程使用后期绑定.以这种方式设置函数"对象(在这种情况下为R3)后,我便能够在prem和Office 365环境中运行RFC.

There's one more twist here and that is that I have another older VBA program that logs into SAP and runs remote function calls that doesn't use SAPFunctionsOCX.SAPFunctions, but rather declares variable R3 as Public R3 As Object and then sets R3 later in the logon code as Set R3 = CreateObject("SAP.Functions")...it does not use OCX. In other words, the old routine uses late binding. When the Functions object (R3 in this case) is set this way, I am able to run RFCs in both on prem and Office 365 environments.

Function LogonProdSAP(Optional SuppressLoginScreen As Boolean)
    Application.ScreenUpdating = False
    '**********************************************
    'Create Server object and Setup the connection for DEV
    '**********************************************
    Set R3 = CreateObject("SAP.Functions")
    If SuppressLoginScreen Then
        R3.Connection.System = "###"
        R3.Connection.HostName = "###################"
        R3.Connection.SystemNumber = "##"
        R3.Connection.Client = "###"
        R3.Connection.User = "##########"
        R3.Connection.Password = "#########"
        R3.Connection.Language = "EN"
'        Call Logger("LogonProdSAP>  " & GetUserName)
    End If
    LogonProdSAP = R3.Connection.logon(0, SuppressLoginScreen)
    If LogonProdSAP <> True Then MsgBox ("Logon error"): Exit Function
End Function

我可以回到这种方式,但是我不想重新配置我刚刚设置的所有代码.此外,我更喜欢早期绑定,因此Intellitype可以显示该对象可用的所有属性/方法.我相信还有其他好处.

I could just go back to doing it this way, but I'd rather not have to reconfigure all of the code I just set up. In addition, I prefer binding early so Intellitype works to show all properties/methods available to that object. I'm sure there are other benefits as well.

要使早期绑定技术在Office 365上运行我必须怎么做?

What do I have to do to get the early-binding technique to work on Office 365?

推荐答案

这是因为您的Office为64位版本,而SAP GUI for Windows最高为7.60版为32位(下一个SAP GUI版本为7.70)应该是64位,因此它应该可以再次工作.)

It's due to the fact that your Office is in 64 bits version, and SAP GUI for Windows up to version 7.60 is in 32 bits (next SAP GUI version 7.70 should be in 64 bits, so it should work again).

您可以通过使用

You have a workaround to make VBA work with SAP GUI 32-bits DLL, by using DLL Surrogate, i.e. by editing the Windows Registry of all incompatible SAP GUI DLL. The original solution was proposed here at SAP Community.

为简化任务,您可以创建我的.REG文件,执行它以自动更新Windows注册表,然后您的VBA宏应该可以正常工作.

To simplify the task, you may create my .REG file, execute it to update automatically the Windows Registry, and your VBA macro should then work.

我在这里复制我的.REG文件:

I duplicate here my .REG file:

; ====================================================================================
; SAP Logon Unicode Control %ProgramFiles(x86)%\SAP\FrontEnd\SAPgui\wdtlogU.ocx {0AAF5A11-8C04-4385-A925-0B62F6632BEC}
; ====================================================================================

[HKEY_CLASSES_ROOT\WOW6432Node\AppID\{0AAF5A11-8C04-4385-A925-0B62F6632BEC}]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{0AAF5A11-8C04-4385-A925-0B62F6632BEC}]
"AppID"="{0AAF5A11-8C04-4385-A925-0B62F6632BEC}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{0AAF5A11-8C04-4385-A925-0B62F6632BEC}]

; ====================================================================================
; SAP Remote Function Call Unicode Control %ProgramFiles(x86)%\SAP\FrontEnd\SAPgui\wdtfuncu.ocx {0AF427E7-03B9-4673-8F21-F33A683BCE28}
; ====================================================================================

[HKEY_CLASSES_ROOT\WOW6432Node\AppID\{0AF427E7-03B9-4673-8F21-F33A683BCE28}]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{0AF427E7-03B9-4673-8F21-F33A683BCE28}]
"AppID"="{0AF427E7-03B9-4673-8F21-F33A683BCE28}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{0AF427E7-03B9-4673-8F21-F33A683BCE28}]

; ====================================================================================
; SAP Logon Control (not Unicode) %ProgramFiles(x86)%\SAP\FrontEnd\SAPgui\wdtlog.ocx {B24944D6-1501-11CF-8981-0000E8A49FA0}
; ====================================================================================

[HKEY_CLASSES_ROOT\WOW6432Node\AppID\{B24944D6-1501-11CF-8981-0000E8A49FA0}]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{B24944D6-1501-11CF-8981-0000E8A49FA0}]
"AppID"="{B24944D6-1501-11CF-8981-0000E8A49FA0}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{B24944D6-1501-11CF-8981-0000E8A49FA0}]

; ====================================================================================
; SAP Remote Function Call Control (not Unicode) %ProgramFiles(x86)%\SAP\FrontEnd\SAPgui\wdtfuncs.ocx {5B076C03-2F26-11CF-9AE5-0800096E19F4}
; ====================================================================================

[HKEY_CLASSES_ROOT\WOW6432Node\AppID\{5B076C03-2F26-11CF-9AE5-0800096E19F4}]
"DllSurrogate"=""

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{5B076C03-2F26-11CF-9AE5-0800096E19F4}]
"AppID"="{5B076C03-2F26-11CF-9AE5-0800096E19F4}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{5B076C03-2F26-11CF-9AE5-0800096E19F4}]

这篇关于执行SAP RFC的VBA程序可在Excel 2016本地部署中运行,但不能在Office 365中运行(运行时错误20080008 ...错误的变量类型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆