我正在尝试为 Excel 更新 Analysis 中的提示(目前我每月手动执行此操作);然而,尽管我从技术名称中获得了价值(尽管我认为这是正确的),但我无法使用下面的代码更改它:
Public currentDateRange As String
Public expectedDateRange As String
Sub GetInfoFROMVariables()
currentDateRange = Application.Run("SAPGetVariable", "DS_1", "ZCALMDEF")
'****Here the MsgBox currentDateRange retrieves the current value for ZCALMDEF, which is "2024/06 - 2024/11".
MsgBox currentDateRange
expectedDateRange = GetNextMonthYear() & " - " & GetFutureMonthYear(6)
MsgBox expectedDateRange
End Sub
Function GetNextMonthYear() As String
Dim startMonth As Date
startMonth = DateAdd("m", 1, Date)
GetNextMonthYear = Format(startMonth, "yyyy/mm")
End Function
Function GetFutureMonthYear(monthsAhead As Integer) As String
Dim futureDate As Date
futureDate = DateAdd("m", monthsAhead, Date)
GetFutureMonthYear = Format(futureDate, "yyyy/mm")
End Function
Sub AtualizarPROMPTAnalysis()
Dim Zeta As Variant
Call GetInfoFROMVariables
If currentDateRange <> expectedDateRange Then
Application.ScreenUpdating = False
'*****Here it does not work, neither the ARRAY or the expectedDateRange commands.
'Application.Run "SAPSetVariable", "DS_1", "ZCALMDEF", Array(GetNextMonthYear(), GetFutureMonthYear(7))
Application.Run "SAPSetVariable", "DS_1", "ZCALMDEF", expectedDateRange
Application.ScreenUpdating = False
RefreshAll = Application.Run("SAPExecuteCommand", "Refresh")
Application.ScreenUpdating = True
'Here it shows normally what is expected "2024/07 - 2024/12"
MsgBox expectedDateRange
End If
End Sub
检查了技术名称,我也知道这是可以的,因为我通常使用 MsgBox currentDateValue 检索该值。
我多次编写和更改此代码,使用 SAPCommunity、MicrosoftCommunity、StackOverFlow 和 ChatGPT 作为支持,但没有成功;不确定这是语法问题还是其他问题。
我认为您出错的是 SAPSetVariable 的参数顺序。它应该是这样的:
Application.Run "SAPSetVariable", "technical_name_of_field", "input value", "INPUT_STRING", "DS_1"
输入类型 (INPUT_STRING) 和数据源 ID (DS_1) 是可选的,实际上在许多情况下最好将它们省略,例如当您处理在工作表之间共享变量的多个数据源时。
阿布拉科斯兄弟