Results 1 to 8 of 8

Thread: Generate TEXT Files from a Control File?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Of course your macro could build the sequential filenames. I wrote a kbase entry to create sequential filenames like Windows does.

    The method using FileCopy() is simple. Checking for folder or file existence is bulk of it.

    [VBA]Sub SeedFileCopy()
    Dim pathSeed As String, seedFilename As String, outFolder As String
    Dim seedFile As String, outPath As String, outFile As String
    Dim cell As Range

    pathSeed = Range("A1").Value2
    If Dir(pathSeed, vbDirectory) = "" Then
    MsgBox pathSeed & " does not exist!", vbCritical, "Macro Ending"
    Exit Sub
    End If

    seedFilename = Range("B1").Value2
    seedFile = AddBackSlash(pathSeed) & seedFilename
    If Dir(seedFile) = "" Then
    MsgBox seedFile & " does not exist!", vbCritical, "Macro Ending"
    Exit Sub
    End If

    outPath = Range("D1").Value2
    If Dir(outPath, vbDirectory) = "" Then
    MsgBox outPath & " does not exist!", vbCritical, "Macro Ending"
    Exit Sub
    End If
    outPath = AddBackSlash(outPath)

    For Each cell In Range("C1", Range("C1").End(xlDown))
    FileCopy seedFile, outPath & cell.Value2
    Next cell
    End Sub

    Function AddBackSlash(str As String) As String
    If Right(str, 1) = "\" Then
    AddBackSlash = str
    Else: AddBackSlash = str & "\"
    End If
    End Function[/VBA]
    Attached Files Attached Files

Posting Permissions

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