Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:57:13+00:00 2026-05-28T07:57:13+00:00

I have two workbooks in Excel 2007, A and B. Within A I have

  • 0

I have two workbooks in Excel 2007, A and B.

Within A I have a function that needs to get certain values from workbook B. I find no way to do this within a function (within a normal sub is no problem, but I need a function – which actually is more complicated than just getting the cell(1,1) )

in A:

function getDataFromB(sheetName,row,col)
   x = Application.run ("E:\B.xlsm!getData",sheetName,row,col)
   getDataFromB = x
end getDataFromB

In B

function getData(sheetName,row,col)
   x=sheets(sheetName).cells(row,col)
   getData = x
end getData

Whenever getData within B is called it looks for sheetName in workbook A – not B. And writing

x = workbooks("E:\B.xlsm").sheets(sheetName).cells(row,col)

does not work

How would I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:57:14+00:00Added an answer on May 28, 2026 at 7:57 am

    TIRED AND TESTED

    Change

    function getDataFromB(sheetName,row,col)
    x = Application.run(“E:\B.xlsm!getData”,sheetName,row,col)
    getDataFromB = x
    end getDataFromB

    to

    Function getDataFromB(sheetName, row, col)
        Dim FilePath As String, FileName As String
        Dim wbTarget As Workbook
        Dim x As Variant
        Dim CloseIt As Boolean
    
        '~~> Set file name and path here.
        FileName = "B.xlsm"
        FilePath = "E:\"
    
        On Error Resume Next
        Set wbTarget = Workbooks(FileName)
    
        If Err.Number <> 0 Then
            '~~> Open the workbook
            Err.Clear
            Set wbTarget = Workbooks.Open(FilePath & "\" & FileName)
            CloseIt = True
        End If
    
        '~~> Check and make sure workbook was opened
        If Err.Number = 1004 Then
            MsgBox "File does not exist!"
            Exit Function
        End If
    
        On Error GoTo 0
    
        x = Application.Run(wbTarget.Name & "!getData", sheetName, row, col)
    
        getDataFromB = x
    
        If CloseIt = True Then
            '~~> If the target workbook was opened by the macro, close it
            wbTarget.Close savechanges:=False
        Else
            '~~> If the target workbook was already open, reactivate this workbook
            ThisWorkbook.Activate
        End If
    End Function
    

    Also in File B Change the code to

    Function getData(sheetName,row,col)
       x=sheets(sheetName).cells(row,col)
       getData = x
    End Function
    

    You need to add “End Function” as I have done above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel 2007 workbook that contains tables of data that I'm importing
I have two workbooks in excel which I copy columns from one to the
I have a PowerPoint 2007 slide with two embedded Excel objects. I want to
I have a huge excel workbook that I've been developing to do some cost
I have some strings in Java (originally from an Excel sheet) that I presume
I have a excel workbook with two sheets. One sheet is maxed out and
We have an Excel workbook which has c# VSTO code in it and two
I have a workbook with two sheets. I would like to format the cell
I have two applications written in Java that communicate with each other using XML
I have two identical tables and need to copy rows from table to another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.