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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a text file to Excel through VB

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
0
0
US
I have a program that creates a text file. I would like to know if anyone can help me with converting the contents of that file to excel. Or is there a way to automactically convert it to excel instead of a text file.

Here is my code

Private Sub mnuConvert_Click()

dlgMain.Filter = "Text Files|*.txt|All Files|*.*"
dlgMain.ShowSave

'Get reference to Outlook
Set objOutlook = New Outlook.Application
Set ns = objOutlook.GetNamespace("MAPI")
Set fldrRoot = ns.Folders.GetFirst

Me.MousePointer = vbArrowHourglass
Open dlgMain.FileName For Output As #1

For Each fldr In fldrRoot.Folders

On Error Resume Next

For Each mi In fldr.Items

Time = mi.ReceivedTime
strName = mi.SenderName
Subject = mi.Subject

' Print Output to file
Write #1, fldr.Name, Time, strName, Subject

Next
Next
Close #1

'Clear Memory
Set mi = Nothing
Set fldr = Nothing
Set fldrRoot = Nothing
Set ns = Nothing
Set objOutlook = Nothing

Me.MousePointer = vbArrow
Call gen_preview_Click
End Sub
 

Search this site there are many examples of using excel.

Good Luck

 

Or use ADO and the JET engine. [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top