View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Referencing Spreadsheet in VBA

Just to elaborate on Williams good answer:

Dim sName as Variant
Dim sh as worksheet
Dim bk as Workbook
set sh = activesheet
sName = application.GetOpenFileName()
if sName = False then exit sub
set bk = Workbooks.Open(sName)

' now you use bk to refer to the workbook

bk.worksheets(1).Range("A1:A10").copy _
destination:=sh.Range("B9")
bk.worksheets(1).Range("F3:G10").copy _
destination:=sh.Range("M5")

'and so forth.
bk.close Savechange:=False

--
Regards,
Tom Ogilvy

"William Horton" wrote:

What Tom suggested will work for you. You will have to assign what the user
inputs in the GetOpenFilename to a variable. The value in the variable will
stay the same until you change it and/or the macro finishes running.

If you want the variable to retain its value between instances of the macro
I would suggest entering whatever the user enters in GetOpenFilename into a
cell in the workbook. You can then refer to that cell whenever you want.
And the value in the cell can be changed by whatever the user types in the
GetOpenFilename if need be.

"Timmy Mac1" wrote:


Thanks Tom.:)

Can I do it in such a way that the macro will keep referring to that
file, rather than have it come up each time?

What I want to do is get the User to select the file which will contain
various ranges I want to copy over to the "working" file?


--
Timmy Mac1
------------------------------------------------------------------------
Timmy Mac1's Profile: http://www.excelforum.com/member.php...o&userid=15188
View this thread: http://www.excelforum.com/showthread...hreadid=535579