LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Calling variable files

go ahead and email what you have

--


Gary


"Ruckus" wrote in
message ...

Gary & Dave,

Thx so much for your responces, links & ideas.

Sounds like it could work, but its to far over my head. I don't have a
clue how to incorporate this stuff.

Going back to changing hard code, when changing files.
Thx anyway


Dave Peterson Wrote:
I'd put each piece of information (workbook, worksheet, address) in
different
cells.

And then I could use some code from John Walkenbach to retrieve the
value:
http://j-walk.com/ss/excel/eee/eee009.txt
Look for either: GetDataFromClosedFile or GetValue.

The code would look kind of like:

Option Explicit
Sub testme()

Dim myLocations As Range
Dim myCell As Range
Dim myValue As Variant

With Worksheets("sheetwithfilenames")
'headers in row 1???
Set myLocations = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In myLocations.Cells
myValue = GetValue(ThisWorkbook.path, _
myCell.Value, _
myCell.Offset(0, 1).Value, _
myCell.Offset(0, 2).Value)

'do something with myvalue
MsgBox myValue

Next myCell

End Sub

'From John Walkenbach
Private Function GetValue(path, file, sheet, range_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(range_ref).Range("A1").Address(, , xlR1C1)

' Execute an XLM macro

GetValue = ExecuteExcel4Macro(arg)

End Function

=======
Another option, if you know the whole path, workbook name, sheet name,
and cell
address is to just build the link:

='C:\my documents\excel\[book1.xls]Sheet1'!$A$1

If the path may change (you used thisworkbook.path), you could have a
macro
build that kind of formula in column D (say) based on what you typed in
columns
A, B, and C.




Ruckus wrote:

Hi,

I have a master workbook which opens several files and pulls data

out,
this all works fine.

The filenames it pulls from are hard coded into the macro. I need

these
to be flexable cause the filenames change ocasionally. Soo what i am
looking for is to add a sheet on my master workbook with names of
files. The macro will then target a cell for the filename to pull

data
from instead of hard coding.

IE: Instead of hardcoding "TestNumber1.xls" this filename will be in

a
cell on sheet2 of the MasterWorkBook, something like
"MasterWorkBook/Sheet2/A1"

Anyone have any clues on how to do this? Or a better way?
Code:
--------------------
'This is copying workbook # 1
Workbooks.Open ThisWorkbook.Path & "\TestNumber1.xls"
LastRow = Range("A65536").End(xlUp).Row
Range("A" & LastRow).EntireRow.Copy
Windows("MasterWorkBook.xls").Activate
Range("A4").Select
ActiveSheet.Paste
Windows("TestNumber1.xls").Activate
Application.CutCopyMode = False
ActiveWindow.Close
--------------------

--
Ruckus

------------------------------------------------------------------------
Ruckus's Profile:

http://www.excelforum.com/member.php...o&userid=27130
View this thread:

http://www.excelforum.com/showthread...hreadid=466463

--

Dave Peterson



--
Ruckus
------------------------------------------------------------------------
Ruckus's Profile:
http://www.excelforum.com/member.php...o&userid=27130
View this thread: http://www.excelforum.com/showthread...hreadid=466463



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling name of Sheet as a Variable? thekeytothedoor Excel Worksheet Functions 1 January 1st 10 08:48 AM
Calling a variable macro Hari Prasadh[_2_] Excel Programming 2 July 30th 05 09:28 AM
Calling a sub with a variable... Gary Phillips[_2_] Excel Programming 1 July 13th 04 10:25 PM
Calling variable file name Michael[_12_] Excel Programming 2 September 16th 03 03:51 PM
saveas calling a variable Douvid Excel Programming 6 July 28th 03 08:46 AM


All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"