excel - 打开文件夹中的所有word文档并将内容复制并粘贴回excel
问题描述
我有两个我尝试过的代码版本略有不同,不幸的是两者都不起作用。我需要一些帮助来弄清楚为什么以及如何做我需要做的事情谢谢
第一段代码不知何故立即结束了循环并且不满足初始条件表达式,尽管我不确定为什么,因为它应该调用该文件夹中的所有 .docx 文件
第二段代码抛出错误 Invalid Use of Property with this line Set wApp.Visible = True 我不知道为什么
第一个版本
Dim folder As String
Dim doc As Document
folder = "G:\GAV\Educational On Assignment Folder\On Assignment Tour Reports\2019\On Tour Questionnaire"
file = Dir(folder & "*.dox*")
r = 1
Do While Len(file) < 0
Set doc = Documents.Open(Filename:=folder & file)
ActiveDocument.Selection.WholeStory
Selection.Copy
Workbooks("Reports Excel").Activate
Cells(1, r).Paste
doc.Close
r = r + 1
file = Dire
Loop
第二版
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim mySource As Object
Set obj = CreateObject("Scripting.FileSystemObject")
Set mySource = obj.getfolder("G:\GAV\Educational On Assignment Folder\On Assignment Tour Reports\2019\On Tour Questionnaire")
For Each file In mySource.Files(Word.Application)
If Len(file.Name) > 0 And InStr(1, file.Name, "$") = 0 Then
Set wApp.Visible = True
Set wDoc = wApp.Documents.Open(muSource & "\" & file.Name, , ReadOnly)
ActiveDocument.Selection.WholeStory
Selection.Copy
Workbooks("Reports Excel").Activate
Cells(1, r).Paste
doc.Close
r = r + 1
wApp.Quit
Set wApp = Nothing
End If
Next file
我需要 Excel 打开文件夹中的每个文件,复制其全部内容并粘贴到 Excel 中的列。应该很简单
解决方案
推荐阅读
- jquery - 将边距 0 添加到带有插入标题元素的偶数元素
- winapi - Win32 编程和字符类型为 UTF-8
- html - 如何使用 CSS 网格将 textarea 扩展到 2 行?
- android - Android上的sqlite中的“WHERE IN”子句是否有任何限制?
- php - Gmail API - ListUsersLabels - 没有邮件总数
- android - 如何通过电话知道当前或不以编程方式
- reactjs - 测试异步获取数据的 React 组件
- python - 在当前目录中找不到文件的 VSCode 文件
- php - 通过phpword中的链接通过数据库导入图像时出错
- android - 对话框片段中的按钮是不可见的,但为什么呢?