Results 1 to 7 of 7

Thread: [RESOLVED] Text to Excel

  1. #1

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Text to Excel

    this can also be done through the Excel object itself:
    VB Code:
    1. Private Sub Command1_Click()
    2.     DelimitedTXTtoXLS "C:\test\test.txt", "~"
    3. End Sub
    4.  
    5. Private Sub DelimitedTXTtoXLS(ByVal sFile As String, ByVal sDelim As String)
    6.     Dim oApp As Object 'Excel.Application
    7.  
    8.     Set oApp = CreateObject("Excel.Application") 'New Excel.Application
    9.     oApp.Workbooks.OpenText FileName:=sFile, OtherChar:=sDelim, Origin:=3, DataType:=1, Other:=True
    10.     With oApp.Workbooks(1)
    11.         .SaveAs FileName:=Left$(sFile, InStrRev(sFile, ".")) & "xls", FileFormat:=-4143
    12.         .Saved = True
    13.         .Close
    14.     End With
    15.     oApp.Quit
    16.     Set oApp = Nothing
    17. End Sub

    code modified from this FAQ

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Text to Excel

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Text to Excel

    I knew there was an easier way. I researched several books last year (before VBforums) and created some version of this solution. Also, not in this code, I need to check some fields values. When I poll tha data from the AS400 via SQL some fields are null, so I check them before converting. Thanx BushMobil, I will test, try, play with your example.

  5. #5

    Thread Starter
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Text to Excel

    Rob, your code and Bush is the same. I need to check some values of some fields and I need to change some width of some cells, Excel does not like Nulls.
    And format some colums. Thanks again

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Text to Excel

    I posted mine first

    Are these new issues you need to do as in a new thread?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Text to Excel

    Sorry, I was on the phone and I clicked after I finished some other work.
    I aaaaaaaaaaaammmmmmmm sorry....hay, we having fun yet?
    As for the issues....I'm fine. The code works, I can alter column format, check values..all good

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width