LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to make text data export to excel in text format.

I have an Excel spreadsheet that I am exporting data from SQL server via DTS. the column in SQL is varchar and the column in Excel is text. But after the
export, in Excel the data is stored as "Number Stored at text" instead of text stored as text.

The same thing happens when I use VB to add the data to Excel. here is the VB Code.

For some reason Excel is looking at the contents of the data and if all fields in a colun consist of all
Excel insist on foramtting as the data "number stored as text"

Thanks in advance for help with this problem.

Johnny

Dim mSql As String
Dim mcnn As New ADODB.Connection
Dim mcnnExcel As ADODB.Connection

Set mcnnExcel = New ADODB.Connection
With mcnnExcel

.Provider = "MSDASQL" ' ODBC dsnless connection
.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=D:\VB_Projects\Excel\1.xls;Extended Properties=Excel 2002 (XP);IMEX=1;FirstRowHasNames=1;MaxScanRows=1;ReadO nly=False;"

.Open
End With

Set mcnn = New ADODB.Connection
With mcnn
.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=admin;" & _
"Initial Catalog=EXCEL; Data Source=HP-A350Y"
End With

Dim oRS As New ADODB.Recordset
oRS.Open "Select * from [Master Form$]", mcnnExcel, adOpenKeyset, adLockOptimistic

'get recordset from Sql Server
mSql = "select * from texcel;"
meof = fn_810OpenRecordset(mSql, mcnn)

'add the records to Excel
Do While Not (mAdoRs.EOF)
oRS.AddNew
For i = 0 To 4 'these fields need to BE TEXT stored as text
oRS.Fields(i).Value = mAdoRs.Fields(i).Value
Next
For i = 5 To 15 ' these fields need to be numeric
oRS.Fields(i).Value = mAdoRs.Fields(i).Value
Next
oRS.Update
mAdoRs.MoveNext
Loop
--
----------------------------------------------
Posted with NewsLeecher v3.0 Final
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------
 
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
How to export plain text from web site to Excel without data conve Jakki Excel Discussion (Misc queries) 1 December 5th 08 12:55 PM
How do I export data in text format with minimum of spaces? [email protected] Excel Discussion (Misc queries) 1 February 12th 07 10:57 PM
How can I export text from excel autoshapes to a text file? Donncha Excel Discussion (Misc queries) 0 July 20th 06 04:58 PM
Export SQL Server data to EXCEL cause all column become TEXT ong Excel Programming 2 September 24th 03 11:49 AM
Export to excel from ASP: Text data interpretation issue Saur Excel Programming 1 August 4th 03 03:53 AM


All times are GMT +1. The time now is 11:47 PM.

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"