Consulting

Results 1 to 5 of 5

Thread: Need: VB code to get values from different closed workbooks

  1. #1

    Need: VB code to get values from different closed workbooks

    Hi,

    In the attached file, column "C" has texts refer to closed workbooks.
    I need a code to get values from these closed workbooks as shown in the attached file.
    Appreciate your urgent help and thanks in advance.


    FormulaLink.xlsx

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you can adopt it like this:

    Option Explicit
    
    'you can extract data from a closed file by using an
    'XLM macro. Credit for this technique goes to John 
    'Walkenback > http://j-walk.com/ss/excel/tips/tip82.htm 
    
    
    Sub GetDataDemo()
    
        Dim FilePath$, FileName$, i&
        Const SheetName$ = "Form"
    
        Application.ScreenUpdating = False
    
        For i = 9 To Cells(Rows.Count, "C").End(xlUp).Row
            FilePath = Left(Cells(i, "C"), InStrRev(Cells(i, "C"), "\"))
            FileName = Mid(Cells(i, "C"), InStrRev(Cells(i, "C"), "\") + 1)
            Cells(i, "G") = GetData(FilePath, FileName, SheetName, "$C$73")
            Cells(i, "H") = GetData(FilePath, FileName, SheetName, "$E$42")
            Cells(i, "I") = GetData(FilePath, FileName, SheetName, "$E$73")
        Next i
    End Sub
    
    
    Private Function GetData(Path, File, Sheet, Address)
        Dim Data$
        Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _    Range(Address).Range("A1").Address(, , xlR1C1)
        GetData = ExecuteExcel4Macro(Data)
    End Function
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    Many thanks my dear friend
    This code was really great and it solved the issue.
    Appreciate.

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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