Importing Data Via A Macro
Thank You - I Will Try You Suggestion
"Tom Ogilvy" wrote:
Dim fName as Variant
Dim fName1 as String
fName = Applicaton.GetOpenFileName(Filefilter:= _
"Text Files (*.txt),*.txt")
if fName = False then
msgbox "Nothing selected"
exit sub
End if
fName1 = Dir(fName)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fName, Destination:=Range("A1"))
.Name = left(fName1,len(fName1)-4)
End With
--
Regards,
Tom Ogilvy
"MWS" wrote in message
...
I need to write a macro to import data from potentially several different
files and need it to be dynamic enough for the user to select the file
they
need. Part of the code I originally used was:
' Keyboard Shortcut: Ctrl+r
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;W:\Pending_Oppty_Report\manager_rejected_010 32005_400a.txt",
Destination _
:=Range("A1"))
.Name = "manager_rejected_01032005_400a"
The issue I'm having is that this hard-code only imports data from the
"manager_rejected_01032005_400a" file and I need to have the macro allow
the
user to select any file within the directory. I think I need to "pause"
the
macro, allow the user to select a file and then resume the importing of
the
data, but am having major problems in completely this - please help.
Any and All Help Is Appreciated - Thank You
|