Thread: Importing File
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Importing File

Public Sub Importflu()
Dim myfile As Variant
Dim bk as workbook, sh as worksheet
worksheets.Add
set sh = ActiveSheet
myfile = Application.GetOpenFilename _
(filefilter:="CSV Files(*.csv),*.csv,All Files (*.*),*.*")
set bk = Workbooks.Open( Filename:=myFile)
bk.worksheets(1).UsedRange.copy Destination:= sh.Range("A1")
bk.Close Savechanges:=False
End Sub

--
Regards,
Tom Ogilvy

"infojmac" wrote in message
...

Hi,

I have the following which allows the user to browse and gives me the
filename

Public Sub Importflu()
Dim myfile As Variant


myfile = Application.GetOpenFilename _
(filefilter:="CSV Files(*.csv),*.csv,All Files (*.*),*.*")


End Sub

What i want is it to then take the data from this file and copy it into
the active workbook - i used the recorder to import specific data but
couldn't marry up my 'myfile' path with the connection:= bit.

So the user should just select the appropiate file and it copies out
the data and sticks it in the new workbook - then i can do the other
sorting macros etc in that workbook.

Any help much appreciated it seems like it should be simple but i've
been trying all mornniing!

Cheers


--
infojmac
------------------------------------------------------------------------
infojmac's Profile:

http://www.excelforum.com/member.php...o&userid=10787
View this thread: http://www.excelforum.com/showthread...hreadid=272048