Consulting

Results 1 to 2 of 2

Thread: Copy value - Another Excel

  1. #1

    Smile Copy value - Another Excel

    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
    Last edited by MaxiMax07; 11-13-2019 at 02:23 PM.

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi MaxiMax07!
    How do you quote the function?
    Here's the right way:

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •