我在一个文件夹中有160个word文档,每个.doc至少包含一个短语,比如'IO:',我希望复制在'IO:'之后开始的所有文件名,并在光标找到Report Output:时停止复制。以下是一个示例输入:
`步骤名称:步骤3- GP00BMDR
Step描述: GENISYS的主要批处理驱动程序,它处理外部事务和内部事务,更新主程序,生成到会计子系统的事务记录,并生成打印文件。
文件规格:输入: 1. GPFTRNW - PHGP.GPFTRNW.TRN.STD.KSDS
2. GPFSCIM – PHGP.GPFSCIM.SCI.KSDS
3. GPFSCSM – PHGP.GPFSCSM.SCS.KSDS
IO: 1. GPFPDGT – PHGP.GPFPDGT.PDG.TRN.KSDS
2. GPFRTXT – PHGP.GPFRTXT.RTX.KSDS报告产出: Nil` `
因此,我希望在.doc之后复制IO:名称和文件名,并在光标到达Report Output:时停止。这是我的剧本:
Sub Ftp_Step_Details()
'this macro checks for FTP in respective steps and copy and writes in a cell along with the corresponding JCL
Dim wordApplication As Word.Application
Dim wordDocument As Word.Document
Dim flag As String
Dim Folder As String, J As String, FLD As Object
Dim Objfile As Object
Dim objfso As Object
Dim intRow As String
Dim contents As String
flag = True
Dim intResult As Integer
Dim strPath As String
'the dialog is displayed to the user
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
'dispaly message box
strPath = Application.FileDialog( _
msoFileDialogFolderPicker).SelectedItems(1)
End If
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\FILE-LIST\File-List.xlsx")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Jcl Name"
objExcel.Cells(1, 2).Value = "File Names"
'Folder = "D:\TEST-IO" 'JCL source goes here
Set objfso = CreateObject("Scripting.FileSystemObject")
Set wordApplication = CreateObject("Word.Application")
intRow = 2
'Opening the file in READ mode
Set FLD = objfso.GetFolder(strPath)
For Each file In FLD.Files
Set Objfile = wordApplication.Documents.Open(file)
Do While Not Objfile.AtEndOfStream
contents = Objfile.ReadLine
If contents Like "*IO:" Then
flag = True
End If
If contents Like "*Report Output:*" Then
flag = False
End If
If flag = True Then
objExcel.Cells(intRow, 1).Value = file.Name
objExcel.Cells(intRow, 2).Value = contents3
intRow = intRow + 1
End If
Loop
Next
Objfile.Close
MsgBox "THANK YOU"
End Sub现在,当我在步骤中测试TYPE MISMATCH的代码时,Set Objfile = wordApplication.Documents.Open(file)为什么呢?
另一个疑问是,Readline函数是否也适用于word VBA?
发布于 2014-09-18 15:36:00
现在,当测试代码时,我在步骤
Set Objfile = wordApplication.Documents.Open(file)中得到了类型错配,为什么呢?
因为File是Scripting.File类型,它是一个对象,而Documents.Open方法需要一个字符串。
你可以试试:
Documents.Open(file.Path)我还有另一个疑问,读行功能在word VBA中也能工作吗?
不,我想不是这样的。
https://stackoverflow.com/questions/25916837
复制相似问题