-1

我正在尝试从文本文件中写入所有内容,但它只写入第一个字符。

这是我的代码:

Sub Main
    Dim TextFile As Integer
    Dim FilePath As String
    Dim FileContent As String

    'File Path of Text File
      FilePath = "C:\Users\Username\Desktop\Clipboard.txt"

    'Determine the next file number available for use by the FileOpen function
      TextFile = FreeFile

    'Open the text file
      Open FilePath For Input As TextFile

    'Store file content inside a variable
      FileContent = Input(LOF(TextFile), TextFile)

    'Report Out Text File Contents
      SendKeys FileContent

    'Close Text File
      Close TextFile

End Sub

我也试过这个,但同样只写第一个字符:

Sub Main
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Dim objTextStream

    Const strFileName = "C:\Users\Username\Desktop\Clipboard.txt"
    Const fsoForReading = 1

    If objFSO.FileExists("C:\Users\Username\Desktop\Clipboard.txt") Then
        'The file exists, so open it and output its contents
        Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
        SendKeys objTextStream.ReadAll
        objTextStream.close
        Set objTextStream = Nothing
    Else
        'The file did not exist
        SendKeys "was not found."
    End If

    'Clean up
    Set objFSO = Nothing
End Sub

请帮忙。谢谢!

4

1 回答 1

0

看起来我需要更多的库才能工作。

我添加了 Microsoft WMI 脚本库、OLE 自动化、VBA 6 和 Visual Basic 运行时对象。我不确定是哪一个修复了它。

于 2017-07-19T23:21:39.577 回答