Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Macro to import CSV file from fixed directory

Hello! I am in the process of developing a quality control spreadsheet based
on CSV files that are exported periodically from a scientific instrument. The
CSV file always goes to the same place on the hard drive. For example,
C:\ICAP\QAQC

I need help on creating a macro button in the Excel 2007 workbook I'm
working on to automatically go to that directory and pull in any CSV file it
finds there. Once it imports the CSV as a sheet in the workbook, then I can
tell it to add the data from the sheet onto a master sheet for charting
purposes. But I do need some help creating a macro button to automatically
pull the CSV in.

Any ideas would be appreciated! Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Macro to import CSV file from fixed directory

If you just record the add sheet and import steps as you perform them, you
get something pretty usable. I just did so with a little sample csv file I
created with the following results. (macro recorder is your FRIEND!) :)

Sub Macro1()

Sheets.Add After:=Sheets(Sheets.Count)
With ActiveSheet.QueryTables.Add(Connection:="TEXT;F:\D ata\MyData.csv", _
Destination:=Range("$A$1"))
.Name = "MyData"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1, 3)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

End Sub

"Anne" wrote:

Hello! I am in the process of developing a quality control spreadsheet based
on CSV files that are exported periodically from a scientific instrument. The
CSV file always goes to the same place on the hard drive. For example,
C:\ICAP\QAQC

I need help on creating a macro button in the Excel 2007 workbook I'm
working on to automatically go to that directory and pull in any CSV file it
finds there. Once it imports the CSV as a sheet in the workbook, then I can
tell it to add the data from the sheet onto a master sheet for charting
purposes. But I do need some help creating a macro button to automatically
pull the CSV in.

Any ideas would be appreciated! Thanks!

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
Import txt file with fixed length from VBA Maurice Excel Programming 3 March 28th 09 10:35 AM
Help with macro. Import text file (fixed width) Sinner Excel Programming 6 March 25th 08 08:24 PM
Fixed length file import?? Trey[_2_] Excel Programming 3 February 9th 06 08:44 PM
import fixed width text file OE Excel Programming 1 June 20th 05 02:56 PM
Import *.asc file into excel fixed width Hartsell Excel Programming 1 February 24th 04 08:15 AM


All times are GMT +1. The time now is 10:14 PM.

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

About Us

"It's about Microsoft Excel"