2015-10-15 195 views
0

繼續運行時錯誤1004「您鍵入的公式包含錯誤。」ExecuteExcel4Macro - 運行時錯誤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" 

缺少什麼我在這裏?

回答

-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 
+0

恐怕不是這樣。該路徑屬於它在原始代碼中的位置。 – Rory

+0

正確,已更正。 – user1016274

0

唯一錯的是你需要使用R1C1引用:(!只要它的其餘部分是正確的,當然)

Ret = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & Range(cellRef).address(True, True, xlR1C1) 

將工作