locked
How to load call value from external workbook? RRS feed

  • Question

  • Hi Friends

    I hope this is relatively easy question for you.

    I try to explain what I am trying to do as simple as I can:

    Imagine I have a workbook open called and saved at C:\TestB.xls

    After pressing a command button on sheet1 I want Cell A1 value from Sheet1 to be loaded from a closed workbook saved at path C:\TestA.xls to the exact same cell in my currently open workbook TestB.xls

    I get as far as

    Sheet1.cells(1,1).value =

    I do not know how to format the path to the source.

    Can anyone help?

    Also does anyone know how to do the same the other way, so i.e save cell A1 value to a closed workbook?

    I would really appreciate your help on that one as I could not find any suitable examples anywhere.

    Thank you

     

    I try to program CommandButton1 on Click event to move cell value from the follow


    Marcin
    Saturday, September 24, 2011 11:51 AM

Answers

  • hi Marcin,
     
    Sub ReadClosedWorkbook()
    sPath = "c:"
    sFile = "TestB.xls"
    sSheet = "Sheet1"
    sLine = 1
    sColumn = 1
     
    Sheets(sSheet).Cells(sLine, sColumn) = ExecuteExcel4Macro _
      ("'" & sPath & "\[" & sFile & "]" & sSheet & "'!R" & sLine & "C" & sColumn & "")
    End Sub
     --
    isabelle
     
    • Proposed as answer by danishani Tuesday, January 31, 2012 5:25 PM
    • Marked as answer by danishani Tuesday, February 7, 2012 7:59 PM
    Saturday, September 24, 2011 12:39 PM