Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Excel Change Text to Date

I am opening a comma-delimited CSV file using:

Workbooks.OpenText FileName:="InFile.csv", _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
IsText), _
Array(2, IsText), Array(3, IsText), Array(4, IsText), Array(5, IsText), _
Array(6, IsText), Array(7, IsText), Array(8, IsText), Array(9,
IsText)), _
TrailingMinusNumbers:=True

One row has the text "5-10" in column H. No matter what I do Excel is
determined to convert that cell to "10-May" and it changes the datatype for
that cell to "Date".

I would hate to have to "dump" Excel and go to pire VB for this project.

Anyone have any ideas how to stop Excel from converting text to date?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Excel Change Text to Date

I found my own answer.

I simply changed the extension from CSV to TXT. Now everything is working
correctly.

Excel can certainly be STUPID at times.



"kahoar" wrote:

I am opening a comma-delimited CSV file using:

Workbooks.OpenText FileName:="InFile.csv", _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
IsText), _
Array(2, IsText), Array(3, IsText), Array(4, IsText), Array(5, IsText), _
Array(6, IsText), Array(7, IsText), Array(8, IsText), Array(9,
IsText)), _
TrailingMinusNumbers:=True

One row has the text "5-10" in column H. No matter what I do Excel is
determined to convert that cell to "10-May" and it changes the datatype for
that cell to "Date".

I would hate to have to "dump" Excel and go to pire VB for this project.

Anyone have any ideas how to stop Excel from converting text to date?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Excel Change Text to Date

Say we have a file:
C:\test folder\x.csv
with records like:
1-1,2-2,3-3,4-4,5-5,6-6,7-7,8-8,9-9,10-10,11-11,12-12

Using the Macro Recorder:

Sub Macro1()
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\t est
folder\x.csv", _
Destination:=Range("A1"))
.Name = "x"
.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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

resulted in no date conversion.
--
Gary''s Student - gsnu200832


"kahoar" wrote:

I am opening a comma-delimited CSV file using:

Workbooks.OpenText FileName:="InFile.csv", _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
IsText), _
Array(2, IsText), Array(3, IsText), Array(4, IsText), Array(5, IsText), _
Array(6, IsText), Array(7, IsText), Array(8, IsText), Array(9,
IsText)), _
TrailingMinusNumbers:=True

One row has the text "5-10" in column H. No matter what I do Excel is
determined to convert that cell to "10-May" and it changes the datatype for
that cell to "Date".

I would hate to have to "dump" Excel and go to pire VB for this project.

Anyone have any ideas how to stop Excel from converting text to date?

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
CHANGE TEXT DATE TO NUMERIC DATE slf Excel Worksheet Functions 5 January 5th 10 10:20 AM
how do i change text format date to date (i.e., mm/yy to mm/dd/yyy lindsey Excel Discussion (Misc queries) 1 July 27th 07 10:05 PM
Excel SHOULD NOT AUTO-CHANGE formated text fields to DATE FIELDS! PSSSD Excel Worksheet Functions 2 August 8th 06 09:31 PM
Change text color of specific date range by macro in Excel Morgan LeFay Excel Programming 1 August 3rd 06 07:51 PM
Change text to date and check against date in cell RW Excel Programming 3 February 2nd 06 03:29 PM


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