Helper function

Private Function GetLargeInput(prompt As String, title As String) As String
    Dim tempFile As String
    Dim fileNum As Integer
    Dim fileContent As String
    Dim txt As String

    ' Create a temporary text file for user input
    tempFile = Environ("TEMP") & "\LargeInput_" & Format(Now, "yyyymmdd_hhnnss") & ".txt"

    ' Open Notepad for the user to paste unlimited text
    Shell "notepad.exe " & tempFile, vbNormalFocus

    ' Wait until the user closes Notepad
    Do While FileLocked(tempFile)
        DoEvents
    Loop

    ' Read file content
    On Error Resume Next
    fileNum = FreeFile
    Open tempFile For Input As #fileNum
    If LOF(fileNum) > 0 Then
        fileContent = Input$(LOF(fileNum), #fileNum)
    End If
    Close #fileNum
    On Error GoTo 0

    ' Return the content to the main macro
    GetLargeInput = Trim(fileContent)

    ' Delete the temporary text file
    On Error Resume Next
    Kill tempFile
    On Error GoTo 0
End Function

Private Function FileLocked(filePath As String) As Boolean
    On Error Resume Next
    Dim ff As Integer
    ff = FreeFile
    Open filePath For Binary Access Read Write Lock Read Write As #ff
    Close #ff
    FileLocked = (Err.Number <> 0)
    Err.Clear
    On Error GoTo 0
End Function

Comments

Popular posts from this blog

fixed

fixed 😃😃😃

babyGirl