Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing File


Hi,

I have the following which allows the user to browse and gives me th
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 int
the active workbook - i used the recorder to import specific data bu
couldn't marry up my 'myfile' path with the connection:= bit.

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

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

Cheer

--
infojma
-----------------------------------------------------------------------
infojmac's Profile: http://www.excelforum.com/member.php...fo&userid=1078
View this thread: http://www.excelforum.com/showthread.php?threadid=27204

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Importing File

Try this:

Public Sub Importflu()
Dim myfile As String
Dim wsSource as Worksheet, wsDestination as Worksheet

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

'open workbook, and get handle on first worksheet
Set wsSource = Wokbooks.Open(myfile).Sheets(1)

'''copy data
'copy single cell value only
wsDestination.Range("A1").Formula =_
wsSource.Range("A1").Formula
'...or copy a chunk, including formats
wsSource.Range("A1:G10").Copy_
Destination:wsDestination.Range("A1")

'close workbook
wsSource.Parent.Close(False)
End Sub

give this a try and get back with any problems,
Cheers.
Dave
-----Original 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?

action=getinfo&userid=10787
View this thread:

http://www.excelforum.com/showthread...hreadid=272048

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing TXT file from web Murtaza Excel Discussion (Misc queries) 0 September 26th 06 03:51 AM
Importing TXT file from web Murtaza Links and Linking in Excel 0 September 26th 06 03:51 AM
Importing a file(s) dan Excel Worksheet Functions 1 August 10th 06 04:08 AM
Importing text file, only option to edit existing file smokey99 Excel Discussion (Misc queries) 8 April 26th 06 09:08 PM
importing prn file Rosson Cain Excel Programming 1 July 21st 03 10:13 PM


All times are GMT +1. The time now is 11:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"