Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Importing TXT file from web | Excel Discussion (Misc queries) | |||
Importing TXT file from web | Links and Linking in Excel | |||
Importing a file(s) | Excel Worksheet Functions | |||
Importing text file, only option to edit existing file | Excel Discussion (Misc queries) | |||
importing prn file | Excel Programming |