⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 doc批量转为txt
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "DOC 批量转 txt ——made by FLY"
   ClientHeight    =   7335
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9330
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   7335
   ScaleWidth      =   9330
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command2 
      Caption         =   "关于软件"
      Height          =   495
      Left            =   7680
      TabIndex        =   15
      Top             =   6600
      Width           =   1455
   End
   Begin VB.CheckBox Check1 
      Caption         =   "输出文件在源目录下"
      ForeColor       =   &H000000FF&
      Height          =   255
      Left            =   5760
      TabIndex        =   11
      Top             =   840
      Width           =   1935
   End
   Begin VB.FileListBox File2 
      Height          =   4050
      Left            =   7560
      TabIndex        =   8
      Top             =   2160
      Width           =   1575
   End
   Begin VB.DriveListBox Drive2 
      Height          =   300
      Left            =   5760
      TabIndex        =   7
      Top             =   1560
      Width           =   1455
   End
   Begin VB.DirListBox Dir2 
      Height          =   4080
      Left            =   5760
      TabIndex        =   6
      Top             =   2160
      Width           =   1695
   End
   Begin VB.CommandButton Command1 
      Caption         =   "转换"
      Height          =   495
      Left            =   3960
      TabIndex        =   3
      Top             =   3480
      Width           =   1335
   End
   Begin VB.DirListBox Dir1 
      Height          =   4080
      Left            =   120
      TabIndex        =   2
      Top             =   2160
      Width           =   1695
   End
   Begin VB.FileListBox File1 
      Height          =   4050
      Left            =   1920
      TabIndex        =   1
      Top             =   2160
      Width           =   1575
   End
   Begin VB.DriveListBox Drive1 
      Height          =   300
      Left            =   120
      TabIndex        =   0
      Top             =   1560
      Width           =   1455
   End
   Begin VB.Label Label7 
      Caption         =   "eternalflier@163.com"
      Height          =   255
      Left            =   3720
      TabIndex        =   14
      Top             =   6840
      Width           =   2175
   End
   Begin VB.Label Label6 
      Caption         =   "copyright @2006 FLY"
      Height          =   255
      Left            =   3720
      TabIndex        =   13
      Top             =   6360
      Width           =   1935
   End
   Begin VB.Label Label5 
      Caption         =   "DOC 批量转 txt ——made by FLY"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   18
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   495
      Left            =   1800
      TabIndex        =   12
      Top             =   120
      Width           =   5655
   End
   Begin VB.Label Label4 
      Caption         =   "文件列表"
      Height          =   255
      Left            =   7680
      TabIndex        =   10
      Top             =   1680
      Width           =   975
   End
   Begin VB.Label Label3 
      Caption         =   "文件列表"
      Height          =   255
      Left            =   1800
      TabIndex        =   9
      Top             =   1680
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "请选择输出文件路径"
      ForeColor       =   &H000000FF&
      Height          =   255
      Left            =   5760
      TabIndex        =   5
      Top             =   1200
      Width           =   1815
   End
   Begin VB.Label Label1 
      Caption         =   "请选择源文件路径"
      ForeColor       =   &H000000FF&
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   1200
      Width           =   1575
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Private Sub Check1_Click()
If Check1.Value = 1 Then
Drive2.Enabled = False
Dir2.Enabled = False
File2.path = File1.path
End If

If Check1.Value = 0 Then
Drive2.Enabled = True
Dir2.Enabled = True
File2.path = Dir2.path
End If

End Sub

'***************************
'转换
Private Sub Command1_Click()
  Dim word     As Object
  Dim fileName     As String
  Dim path As String
  Dim path2 As String
  Dim n As Integer

If Check1.Value = 1 Then



  
  Set word = CreateObject("word.Application")
  
  

For n = 0 To File1.ListCount - 1 '从列表框的第一个项目找到最后一个项目

  path = Dir1.path
  If Dir1.path <> Drive1.Drive & "\" Then

  fileName = path & "\" & File1.List(n) '依次输出该文件夹中指定类型的文件名,可以按照自己的需要输出到一个文本文件中,或者自己其他指定
  Else
    fileName = path & File1.List(n) '依次输出该文件夹中指定类型的文件名,可以按照自己的需要输出到一个文本文件中,或者自己其他指定

  End If
  
  Call mname(File1.List(n))
  word.Documents.Open fileName
  word.ActiveDocument.SaveAs fileName:=path & mainname, FileFormat:=2      '存储为“txt”格式文件


  word.ActiveDocument.Close
  
  Next n
  
  word.Quit


Else



  
Set word = CreateObject("word.Application")
  
  

For n = 0 To File1.ListCount - 1 '从列表框的第一个项目找到最后一个项目

   path = Dir1.path
   path2 = Dir2.path
  

   
  
  
   If Dir1.path <> Drive1.Drive & "\" Then

     fileName = path & "\" & File1.List(n) '依次输出该文件夹中指定类型的文件名,可以按照自己的需要输出到一个文本文件中,或者自己其他指定
    Else
      fileName = path & File1.List(n) '依次输出该文件夹中指定类型的文件名,可以按照自己的需要输出到一个文本文件中,或者自己其他指定

  End If
  
  Call mname(File1.List(n))
      word.Documents.Open fileName
  
     If Dir2.path <> Drive2.Drive & "\" Then
  
   word.ActiveDocument.SaveAs fileName:=path2 & "\" & mainname, FileFormat:=2      '存储为“txt”格式文件
     Else
   word.ActiveDocument.SaveAs fileName:=path2 & mainname, FileFormat:=2       '存储为“txt”格式文件
    End If

     word.ActiveDocument.Close
  
  Next n
  
  word.Quit


File2.Refresh


MsgBox ("文件已经转换完毕")

End If



End Sub



Private Sub Command2_Click()
Form2.Show
End Sub

'***************************

Private Sub Dir1_Change()

File1.path = Dir1.path



End Sub

Private Sub Dir2_Change()

File2.path = Dir2.path



End Sub


Private Sub Drive1_Change()

On Error GoTo error

Dir1.path = Drive1.Drive


Exit Sub
error:

MsgBox ("设备不可用!")

Drive1.Drive = "c:"
End Sub

Private Sub Drive2_Change()

On Error GoTo error

Dir2.path = Drive2.Drive


Exit Sub
error:

MsgBox ("设备不可用!")

Drive2.Drive = "c:"
End Sub

Private Sub Form_Load()



File1.Pattern = "*.doc"   ';   *.bat"  显示指定类型文件

File2.Pattern = "*.txt"

File1.path = Dir1.path

File2.path = Dir2.path

Dir1.path = "c:\"

Dir2.path = "c:\"




End Sub


Function mname(Full_Name As String) As String

Dim i     As Integer
Dim strMainName     As String
    
  strMainName = Full_Name
  fileName = Full_Name
  For i = 1 To Len(fileName)
          If Right(strMainName, 1) = "." Then
  strMainName = Left(strMainName, Len(strMainName) - 1)
                  Exit For
          Else
                strMainName = Left(strMainName, Len(strMainName) - 1) '减1个字符
          End If
  Next i


mainname = strMainName
    
End Function
  





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -