继续获取运行时错误1004“您输入的公式包含错误。”
MyCode:
Private Sub UserForm_Initialize()
Dim wbPath, wbName, wsName, cellRef, Ret As String
Set xlApp = CreateObject("Excel.application")
wbPath = "N:\BVN\1W\02 GpDS\04 Sp\03 Horeca\04 SBC\02 Private\01 Boekhouding sbc\"
wbName = "TEGOEDEN-AVOIR.xls"
wsName = "CIS-A4"
cellRef = "F6"
Ret = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & Range(cellRef).Address(True, True)
Ret = CStr(Ret)
Me.Label11.Caption = xlApp.ExecuteExcel4Macro(Ret)
End Sub
我在变量上添加了一个监视器似乎没问题:
"'N:\BVN\1W\02 GpDS\04 Sp\03 Horeca\04 SBC\02 Private\01 Boekhouding sbc\[TEGOEDEN-AVOIR.xls]CIS-A4'!$F$6"
我在这里缺少什么?
答案 0 :(得分:0)
唯一不对的是你需要使用R1C1参考:
Ret = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & Range(cellRef).address(True, True, xlR1C1)
会起作用(只要其余部分当然是正确的!)
答案 1 :(得分:-1)
该路径属于工作簿文件名,不在其前面:
另一个提示(不会导致错误):这个
Dim wbPath, wbName, wsName, cellRef, Ret As String
将定义4个Variants
和一个string
。你真正想要的是
Dim wbPath As String, wbName As String, wsName As String, cellRef As String, Ret As String