Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Data Out to an Excel File

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
US
I have been writing information out from my VB6 application to text files, but I have a request to send them to Excel. The problem I having is that the three columns all go to column A in Excel.

Is there anyway to break up the three columns so that they go to columns A, B, C respectively?

Here is my code:

Open "C:DDNotRegNot_V_Or_P.txt" For Append As #intFileNum
Print #intFileNum, RSMaxTest!Issn; "|"; _
RSMaxTest!dispatch_date; "|"; _
RSMaxTest!dispatch_flag
Close #intFileNum

 
Try this. It uses an OLE-embedded Excel sheet. It assumes you stuff the data into an array first (you'll have to code that yourself), and dump the whole array into the spreadsheet. You don't HAVE to use an array, but it's a lot more efficient.

/Cy

Dim oSheet as object
Dim oBook as object
Dim ValueArray(5,5)

Populate_Value_Array

form1.OLE1.CreateEmbed vbNullString, "Excel.Sheet"
form1.OLE1.SizeMode = vbOLESizeAutoSize

Set oBook = form1.OLE1.object
Set oSheet = oBook.Sheets(1)

oSheet.Range("A1:E" & CtrRow% + 1).Value = ValueArray

oSheet.Range("A1:E1").Select
With oBook.Application.Selection
.HorizontalAlignment = xlCenter
.Font.Bold = True
.Font.Size = 12
.Interior.ColorIndex = 6
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
End With

oSheet.Range("E6").Select

With oBook.Application.Selection
.Formula = "=SUM(E1:E6)"
End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top