Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Gary L Brown
 
Posts: n/a
Default CSV - Macro - Template

Suggestion:
1) Using Windows Explorer, change the name of the csv file to txt.
Example: Change MyFile.csv to MyFile.txt
2) Start a macro recording and pull up MyFile.txt.
The Text Import Wizard will appear.
3) Follow the Wizard and change data to the appropriate
type such as text
4) Stop the macro recording.

The macro will look something like this...

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/7/2005 by Gary_Brown
'

'
Workbooks.OpenText Filename:="D:\Temp\MyFile.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 2), _
Array(3, 2), Array(4, 1))
Cells.EntireColumn.AutoFit
End Sub

5) Change the macro to something like this....
(The only change is manipulation of the file name)
[Assume the file is downloaded to the same folder each day]
[Assume the file name changes daily]

'/=============================================/
Sub GetMyFile()
Dim strFileName As String

strFileName = _
Application.InputBox(Prompt:="Enter File Name: ", _
Default:="MyFile.txt", Type:=2)

Workbooks.OpenText Filename:="D:\Temp\" & strFileName, _
Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=True, Semicolon:=False, Comma:=False, Space:=False, _
Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 2), _
Array(3, 2), Array(4, 1))
Cells.EntireColumn.AutoFit

End Sub
'/=============================================/


6) Put this macro in your Personal.xls or in a workbook that you will open
daily just prior to pulling in your text file.

HTH,
--
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"jeridbohmann" wrote:

We have AS400 which outputs a report to a csv daily.
Now you open the csv spreadhseet and the data is right, but the format is
wrong.
Column A too short, Column B needs to be numberic (so we can use a comma in
the 100's), Column C is to short, etc..
We open this daily, do all that formatting just to make it look right. Is
there a way to make a Macro stay in a csv? Any other suggestions? I want to
make this automated if possible.

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
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Macro Template File LizW Excel Worksheet Functions 0 September 16th 05 06:26 PM
Inserting Filtered RC cell information into other worksheets Dennis Excel Discussion (Misc queries) 10 July 30th 05 01:54 AM
Template in Excel prettytwin1 New Users to Excel 1 March 9th 05 09:22 PM
how do i change the expense statement template macro Mad2691 Excel Worksheet Functions 1 January 28th 05 01:21 PM


All times are GMT +1. The time now is 05:27 AM.

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"