PDA

View Full Version : [SOLVED] Copy value - Another Excel



MaxiMax07
11-13-2019, 12:35 PM
Hi everyone!

I'm new to VBA. First, I'm trying to create a simple formula but I can't make it work... I want to be able to read a cell from another Excel file and output the value.
Can you help me make it work?
I have put an exemple path directly into the function, to minimize the chance of errors.


Function Eval2(Path As String)
Application.Volatile
'Application.ScreenUpdating = False
Dim wkb As Workbook
Set wkb = Workbooks.Open("C:\Users\colombiem\Google Drive\Immeuble\Finances\Finance 2019.xlsx")
Debug.Print wkb.Worksheets(1).Range("J5").Value
Eval2 = wkb.Worksheets(1).Range("J5").Value
Debug.Print Eval2
wkb.Close False
Set wkb = Nothing
'ErrHandler:
' Application.EnableEvents = True
' Application.ScreenUpdating = True
End Function


When I create the function as an executable, it works...
I'm trying to understand why the function doesn't work.



Sub test()
Application.ScreenUpdating = False
Set wkb = Workbooks.Open("C:\Users\colombiem\Google Drive\Immeuble\Finances\Finance 2019.xlsx")
Dim Eval As Integer
Eval = wkb.Worksheets(1).Range("J5").Value
Debug.Print Eval
Workbooks("Budget 2019.xlsm").Worksheets("Finances 2019").Activate
ActiveSheet.Range("A9").Value = Eval
Debug.Print ActiveSheet.Range("A10").Value
wkb.Close False
Set wkb = Nothing
ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


Thanks a lot :yes

大灰狼1976
11-14-2019, 12:41 AM
Hi MaxiMax07!
How do you quote the function?
Here's the right way:


sub test
debug.print Eval2(variable of Path)
end sub