patrickão
07-04-2015 12:51:25
Olá Pessoal.
Tenho um arquivo com a função GetInfoFromClosedFile . Porém quando executo o programa, essa função não está pegando o valor da célula especificada, retornando apenas o valor ZERO independente do valor existente na posição Cells(1, 1)
Segue o código
Sub Teste()
'todas variáveis declaradas como string
MyFile = "Arquivo.xls"
FolderName = "C:\User\Desktop"
Row = 1
Column = 1
Dado = GetInfoFromClosedFile(FolderName, MyFile, "Plan1", Row, Column)
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------
Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
wbName As String, _
wsName As String, _
Row As Integer, _
j As Integer) As Variant
Dim cellRef As String, col As Integer
Dim arg As String
GetInfoFromClosedFile = ""
col = j + 1
If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
If Dir(wbPath & "\" & wbName) = "" Then Exit Function
cellRef = Cells(Row, col).Address
arg = "'" & wbPath & "[" & wbName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function
Tenho um arquivo com a função GetInfoFromClosedFile . Porém quando executo o programa, essa função não está pegando o valor da célula especificada, retornando apenas o valor ZERO independente do valor existente na posição Cells(1, 1)
Segue o código
Sub Teste()
'todas variáveis declaradas como string
MyFile = "Arquivo.xls"
FolderName = "C:\User\Desktop"
Row = 1
Column = 1
Dado = GetInfoFromClosedFile(FolderName, MyFile, "Plan1", Row, Column)
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------
Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
wbName As String, _
wsName As String, _
Row As Integer, _
j As Integer) As Variant
Dim cellRef As String, col As Integer
Dim arg As String
GetInfoFromClosedFile = ""
col = j + 1
If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
If Dir(wbPath & "\" & wbName) = "" Then Exit Function
cellRef = Cells(Row, col).Address
arg = "'" & wbPath & "[" & wbName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function