Consulting

Results 1 to 3 of 3

Thread: Solved: Create User Defined Text File

  1. #1

    Solved: Create User Defined Text File

    [VBA]Sub CreateAfile()
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.CreateTextFile("c:\testfile.txt", True)
    f.WriteLine ("This is a test.")
    f.Close
    End Sub[/VBA]

    I can use VBA to Create a text file via the manner above. But the problem is that the programmer dictates the location and file name in the code. Is there a way to have the user define the folder and file name with a dialog box? If so, how?

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Use the GetSaveAsFilename dialog.

    [vba]Sub CreateAfile()
    Dim vntSaveName as Variant

    vntSaveName = application.GetSaveAsFilename
    if vntSaveName = "False" then exit sub

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.CreateTextFile(vntSaveName, True)
    f.WriteLine ("This is a test.")
    f.Close
    End Sub [/vba]
    Cheers
    Andy

  3. #3
    That worked nicely.

    Thanks!

Posting Permissions

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