[RESOLVED] Creating Text Files From Excel's VBA-VBForums
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 06:33 PM. Reason: Fixed vbcode tags

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

    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!
    Star Wars Gangsta Rap 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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.