Results 1 to 3 of 3

Thread: [RESOLVED] Creating Text Files From Excel's VBA

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    Resolved [RESOLVED] Creating Text Files From Excel's VBA

    So, (with some help, thx Si) I've successfully used the code below to create Text files from Excel's VBA. I have a new problem though.

    How do I pass more than one line of text to the file?
    Ideally I'ld like to be able to pass an ENTER keystroke(within "myString") and continue sText (myString) on a new line.


    VB Code:
    1. Dim sFile As String
    2. Dim sText As String
    3. Dim iFileNum As Integer
    4.  
    5. sFile = "C:\(path)\Textfile.txt"
    6.  
    7. sText = "myString"
    8.  
    9. iFileNum = FreeFile
    10. Open sFile For Output As iFileNum
    11. Print #iFileNum, sText
    12. Close #iFileNum
    Last edited by RobDog888; Jun 7th, 2006 at 05:33 PM. Reason: Fixed vbcode tags

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

    Re: Creating Text Files From Excel's VBA

    Each print statement will end with a new line.
    VB Code:
    1. Open sFile For Output As iFileNum
    2.     Print #iFileNum, sText
    3.     Print #iFileNum, "More text on next line"
    4.     Print #iFileNum, "Etc."
    5. Close #iFileNum
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    48

    Re: [RESOLVED] Creating Text Files From Excel's VBA

    Wow That was fast! Thanks for the help. Worked great.

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