retrun the value from a cell in another workbook that is in a URL path and the URL path is in a cell

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi Everyone, sorry for the long title. I am trying to return a value that is in a closed workbook that is from a URL path. AND the URL path is in a cell

My Macro scrips is like so:

Code:
Sheets("Schedule Dashboard").Range("F4") =
after that needs to come the path, which is located in sheet2 A1. the sheet to look in on the closed workbook (from the path) is Week 1$AT$1.


Hope my explanation was clear enough. The reason I cannot just input the path is the path is created in cell A1 and is always different.

Thanks in advacne

sd
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
try setting the path to a variable (which gets it from a1) then use that to call the value. from what i read its in another separte workbook yes? not another sheet?
 
Upvote 0
try setting the path to a variable (which gets it from a1) then use that to call the value. from what i read its in another separte workbook yes? not another sheet?


Thanks a ton for the reply!! How would that look if i was trying to say get the value from Workbook(Path is in A1) Sheet "Week 1" Cell AT1 and place the value retried in cell A2 of the active workbook?

sd
 
Upvote 0
something like the below, put this in a module

Code:
Private Function GetValue(path, file, sheet, ref)
'   Retrieves a value from a closed workbook
    Dim arg As String
'   Make sure the file exists
    If Right(path, 1) <> "\" Then path = path & "\"
    If Dir(path & file) = "" Then
        GetValue = "File Not Found"
        Exit Function
    End If
'   Create the argument
 
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
      Range(ref).Address(, , xlR1C1)
 
    MsgBox arg
 
'   Execute an XLM macro
    GetValue = ExecuteExcel4Macro(arg)
 
End Function

then under your event (button,form activate which ever) put

Code:
dim dsa as variant
 
  p = thisworkbook.sheets("Sheet1").range("A1").value
'ensure this is full path with \ at the end
   f = "b.xlsm" 'name of file
   s = "Week 1" 'sheet of file
   a = "AT1" 'where you are looking
   dsa = GetValue(p, f, s, a)
thisworkbook.sheets("Week 1").range("A2").vaule = dsa

may need tweaking as I havent tested yet (sorry)
 
Upvote 0
something like the below, put this in a module

Code:
Private Function GetValue(path, file, sheet, ref)
'   Retrieves a value from a closed workbook
    Dim arg As String
'   Make sure the file exists
    If Right(path, 1) <> "\" Then path = path & "\"
    If Dir(path & file) = "" Then
        GetValue = "File Not Found"
        Exit Function
    End If
'   Create the argument
 
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
      Range(ref).Address(, , xlR1C1)
 
    MsgBox arg
 
'   Execute an XLM macro
    GetValue = ExecuteExcel4Macro(arg)
 
End Function

then under your event (button,form activate which ever) put

Code:
dim dsa as variant
 
  p = thisworkbook.sheets("Sheet1").range("A1").value
'ensure this is full path with \ at the end
   f = "b.xlsm" 'name of file
   s = "Week 1" 'sheet of file
   a = "AT1" 'where you are looking
   dsa = GetValue(p, f, s, a)
thisworkbook.sheets("Week 1").range("A2").vaule = dsa

may need tweaking as I havent tested yet (sorry)


Thank you so much for helping. Ive ben struggling with this for a while now. :)

Im getting an error of "Runtime error 52 Bad Filename or Number"

Here is what I used. Maybe you can see an error?

Code:
Private Function GetValue(path, file, sheet, ref)
'   Retrieves a value from a closed workbook
    Dim arg As String
'   Make sure the file exists
    If Right(path, 1) <> "\" Then path = path & "\"
    If Dir(path & file) = "" Then
        GetValue = "File Not Found"
        Exit Function
    End If
'   Create the argument
 
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
      Range(ref).Address(, , xlR1C1)
 
    MsgBox arg
 
'   Execute an XLM macro
    GetValue = ExecuteExcel4Macro(arg)
 
End Function

Code:
Sub Schedule_Posted_YESNO()
Dim dsa As Variant
 
  p = ThisWorkbook.Sheets("Schedule Dashboard").Range("R34").Value
'ensure this is full path with \ at the end
   f = "AugustSchedule7886.xlsx" 'name of file
   s = "Week 1" 'sheet of file
   a = "AT1" 'where you are looking
   dsa = GetValue(p, f, s, a)
ThisWorkbook.Sheets("Schedule Dashboard").Range("F4").vaule = dsa
End Sub

Schedule Dashboard R34 has: (changed part of the url cause is for work)
http://infonet.abcdefg.com/sites/retail/WFM/West/Pacific Northwest/Seattle Metro/ (with out the "AugustSchedule7886.xlsx", should it have this?)

Thanks for hangin in there with me. :)

sd
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top