View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Reference filename used in code from cell

You can do that, but you would need to be more specific where sheet M is. If
it is in the workbook containing the code, you could change
Windows("060313_hc.xls").Activate
to
Windows(thisworkbook.Worksheets("M").Range("A1").V alue).Activate

That said, it is usually unecessary to activate workbooks and worksheets to
work with them

set bk = workbooks(thisworkbook.Worksheets("M").Range("A1") .Value)
bk.Worksheets(1).Range("D7").Value = 21

as an example.

--
Regards,
Tom Ogilvy



" wrote:

Hi all

I am using the code below to update a spreadsheet with information from
another. What I would like to know is the line with the <<<<<<< is
there any way to reference that filename from a cell instead of
specifying it in the code. For example the filename would be contained
in a sheet called 'M' in cell 'A1'. That way we could enter the name of
the file we want to update into a cell to save messing with the code at
a future date. Thanks in advance

Sheets("ASC").Select
ChDir "\\w2k6001\shared\csdgapp\miteam\Manpower"
Workbooks.Open Filename:= _
"\\w2k6001\shared\CSDGAPP\miTeam\Manpower\AManpowe rhcv0.2.xls"
Sheets("ASC").Select
Range("D7").Select
ActiveWindow.TabRatio = 0.943
ActiveWindow.SmallScroll ToRight:=5
ActiveWindow.SmallScroll Down:=69
Range("D7:Q106").Select
Selection.Copy
Windows("060313_hc.xls").Activate <<<<<<<<<<<
Range("D7").Select
ActiveSheet.Paste