网页知识大全网站改版中:主站将改版成软件下载,PPT,个人简历等等内容,现有内容保留到旧版中去。
您所在的位置:首页 > 实例 > 正文

实用功能1-50到txt

作者: 来源:原创 日期:2023/9/2 22:28:00 人气:21 加入收藏 标签:实用功能1-50到txt

Sub SaveTxtFiles()        Dim Path As String      Dim FileName As String      Dim TextContent As String      Dim i As Integer            ' 设定文件夹路径      Path = "D:\9-2-jxw\"            ' 检查文件夹是否存在      If Not FolderExists(Path) Then          MsgBox "文件夹不存在,请检查路径是否正确。", vbCritical, "错误"          Exit Sub      End If            ' 循环遍历A1:B50区域,创建并保存txt文件      For i = 1 To 50                    ' 获取文件名和内容          FileName = Range("A" & i).Value          TextContent = Range("B" & i).Value                    ' 创建并保存txt文件          CreateTextFile Path & FileName, TextContent                Next i            MsgBox "所有txt文件已成功保存到指定文件夹。", vbInformation, "完成"         End Sub     ' 检查文件夹是否存在   Function FolderExists(ByVal FolderPath As String) As Boolean      On Error Resume Next      If Not Dir(FolderPath, vbDirectory) = "" Then FolderExists = True Else FolderExists = False   End Function     ' 创建并保存txt文件   Sub CreateTextFile(ByVal FilePath As String, ByVal FileContent As String)      Dim FileNumber As Integer      FileNumber = FreeFile()      Open FilePath For Output As #FileNumber      Print #FileNumber, FileContent      Close #FileNumber   End Sub

本文网址:http://clewo.net/shili/59158.html
读完这篇文章后,您心情如何?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0