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

I am working on a project that will read data from a *.csv file and
process it in a new workbook. The new workbook will have the macro to
handle this process. I have a couple questions:

I am assuming a file must be open in order to extract data.

Does the *.csv file have to be activated after the file is open in order
to begin processing data? How can this be done without losing focus
from the new workbook?

Thanks,
GeoK
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Extracting data...

Right from the Recorder:

Sub Macro1()
ChDir "C:\"
Workbooks.Open Filename:="C:\x.csv"
Windows("Book1").Activate
Range("I7").Select
End Sub

--
Gary''s Student - gsnu2007L


"George" wrote:

I am working on a project that will read data from a *.csv file and
process it in a new workbook. The new workbook will have the macro to
handle this process. I have a couple questions:

I am assuming a file must be open in order to extract data.

Does the *.csv file have to be activated after the file is open in order
to begin processing data? How can this be done without losing focus
from the new workbook?

Thanks,
GeoK

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Extracting data...

Another version, from one of my workbooks- this copies the entire CSV into a
target worksheet in your 'active' workbook.

Sub Grab_Current_Raw_Data()
Dim wb As Workbook
Dim ws As Worksheet
Dim fn As String
fn = "\\drive\path\folder\filename.csv"
Set ws = Sheet1 'Worksheets("Data")
Set wb = Workbooks.Open(fn)
wb.Worksheets(1).Cells.Copy
ws.Activate
ws.Range("A1").PasteSpecial
wb.Close SaveChanges:=False
End Sub


"Gary''s Student" wrote:

Right from the Recorder:

Sub Macro1()
ChDir "C:\"
Workbooks.Open Filename:="C:\x.csv"
Windows("Book1").Activate
Range("I7").Select
End Sub

--
Gary''s Student - gsnu2007L


"George" wrote:

I am working on a project that will read data from a *.csv file and
process it in a new workbook. The new workbook will have the macro to
handle this process. I have a couple questions:

I am assuming a file must be open in order to extract data.

Does the *.csv file have to be activated after the file is open in order
to begin processing data? How can this be done without losing focus
from the new workbook?

Thanks,
GeoK

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Extracting data...

Very good - nice and crisp.
--
Gary''s Student - gsnu200856


"ker_01" wrote:

Another version, from one of my workbooks- this copies the entire CSV into a
target worksheet in your 'active' workbook.

Sub Grab_Current_Raw_Data()
Dim wb As Workbook
Dim ws As Worksheet
Dim fn As String
fn = "\\drive\path\folder\filename.csv"
Set ws = Sheet1 'Worksheets("Data")
Set wb = Workbooks.Open(fn)
wb.Worksheets(1).Cells.Copy
ws.Activate
ws.Range("A1").PasteSpecial
wb.Close SaveChanges:=False
End Sub


"Gary''s Student" wrote:

Right from the Recorder:

Sub Macro1()
ChDir "C:\"
Workbooks.Open Filename:="C:\x.csv"
Windows("Book1").Activate
Range("I7").Select
End Sub

--
Gary''s Student - gsnu2007L


"George" wrote:

I am working on a project that will read data from a *.csv file and
process it in a new workbook. The new workbook will have the macro to
handle this process. I have a couple questions:

I am assuming a file must be open in order to extract data.

Does the *.csv file have to be activated after the file is open in order
to begin processing data? How can this be done without losing focus
from the new workbook?

Thanks,
GeoK

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Extracting data...

you don't need to open it in the excel application...you could read the data
in as a textstream - means using the Microsoft Scripting Runtime.
You'll need to open a connection to the file though.

in the dev environment, set a reference the Microsoft Scripting Runtime
add this code to a standard module:

Option Explicit
Const sFILE As String = "C:\temp\test.csv"
Sub GetData()
Dim textst As TextStream
Dim data As Variant
Dim text As String
Dim rowindex As Long
With New FileSystemObject
Set textst = .OpenTextFile(sFILE, ForReading, False)
Do Until textst.AtEndOfStream
rowindex = rowindex + 1
text = textst.ReadLine
data = Array(Split(text, ","))
With Cells(rowindex, 1)
.Value = text
.TextToColumns Cells(rowindex, 1)
End With
Loop
textst.Close
Set textst = Nothing
End With
End Sub

"George" wrote in message
...
I am working on a project that will read data from a *.csv file and
process it in a new workbook. The new workbook will have the macro to
handle this process. I have a couple questions:

I am assuming a file must be open in order to extract data.

Does the *.csv file have to be activated after the file is open in order
to begin processing data? How can this be done without losing focus from
the new workbook?

Thanks,
GeoK




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Extracting data...

Gary''s Student wrote:
Very good - nice and crisp.


Thank you for the information. Very helpful!
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
Extracting data debinnyc Excel Discussion (Misc queries) 2 August 19th 09 04:10 PM
extracting data from one sheet based on data in another - VLookup? des Excel Worksheet Functions 3 February 4th 09 07:27 PM
etract unique data from multiple workbooks after extracting data [email protected] Excel Programming 3 December 27th 07 06:56 AM
Text parsing - Extracting data from inconsistent data entry format. u473 Excel Programming 2 August 26th 07 01:51 AM
Extracting Data for .Txt Files By Unique Field Data La Excel Discussion (Misc queries) 3 July 17th 06 01:30 PM


All times are GMT +1. The time now is 01:25 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"