Open Files via InputBox - thx
Now it works. Many thanks!
Maria
-----Original Message-----
sName contains a value like "C:\Myfolder\MyFile.xls"
I provided a variable that holds a reference to the newly
opened file
Dim sName as String
Dim rng as Range
set rng = ActiveCell
chDrive "C"
ChDir "C:\Myfolder"
sName = Application.GetOpenfileName()
if sName < "False" then
set bk = Workbooks.Open(sName)
else
exit sub
End if
rng.Value = bk.Sheets("Hourly Data") _
.Range("CU1").Value
or if you need the filename, after opening:
sName = bk.name
also when the workbook is opened, it will be the
activeworkbook unless you
do something to make it not the activeworkbook.
--
Regards,
Tom Ogilvy
"Maria" wrote in
message
...
Thank you, Tom!
Now I have problems adressing the workbook. I tried the
following:
ActiveCell.Value = (Workbooks(sName).Sheets("Hourly
Data").Range("CU1").Value)
This produces a run time error - what can I do?
Thanks for your help again ...
Maria
-----Original Message-----
use the file open dialog
Dim sName as String
chDrive "C"
ChDir "C:\Myfolder"
sName = Application.GetOpenfileName()
if sName < "False" then
set bk = Workbooks.Open(sName)
else
exit sub
End if
msgbox bk.Name & " has been opened"
--
Regards,
Tom Ogilvy
"Maria" wrote in
message
...
Hello there,
I would like to create an InputBox that gives the
user
the
possibility to decide which file to open - he/she
should
type in the whole path. Is that possible, and if it
is
how
am I going to do it? Then, if the macro should work
with
the open file, how can I adress it? (The files look
all
the same but have slightly different names and
different
data ...)
Thanks for your help!
Maria
.
.
|