我正在尝试从此页面调整VBA copy formatted text into access using vba,以便它可以遍历选定的所有文件或特定文件夹中的所有文件。这可能吗?谢谢。将格式化的Word文本复制到Access中
0
A
回答
1
您可以执行以下两项操作之一:不要拆分filepicker函数和导入函数,也不要从filepicker函数返回集合或数组。
我要选择教育价值后者:
选择文件
Public Function FilesToOpen() As Collection
' This function will essentially allow you to browse to MS-Word document
' and then store the path of that file for use in the GetWordContent function
Dim fDialog As Object 'Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(3)
Set FilesToOpen = New Collection
With fDialog
.AllowMultiSelect = True
.Title = "Select Word document to import"
.Filters.Clear
.Filters.Add "Word files", "*.doc?"
If _
.Show = True _
Then
For Each varFile In .SelectedItems
FilesToOpen.Add varFile
Next
End If
End With
End Function
并打开它们
Private Sub cmdGetWordData_Click()
' This subroutine runs on your command button; it will call both the FileToOpen function and GetWordContent subroutine
' to retrieve the text contents of your chosen MS-Word Document.
' It will then store both the path the text contents of of your chosen MS-Word Document in 2 fields in a table in Access.
' NOTE: this code assumes that your Access database has:
' - a table called tblWordDump
' - a memo text field in this table called WordDocDataSrc to store the path of MS-Word file imported
' - a memo text field in this table called WordDocData with the TextFormat property set to "Rich Text",
' which will store the text and text formating of the MS-Word file imported
Dim collFiles As Collection
Dim strWordContent As Variant
' Select files via File Dialogue
Set collFiles = FilesToOpen
Dim oneFile As Variant
' Conditionals when a file was or wasn't selected
If _
collFiles.Count <> 0 _
Then
For Each oneFile In collFiles
DoCmd.GoToRecord , , acNewRec
GetWordContent CStr(oneFile)
Next oneFile
MsgBox "Import Successful", vbInformation Or vbOKOnly
Else
MsgBox "No File Selected", vbExclamation Or vbOKOnly
End If
End Sub
请注意,我试图改变尽可能少,并且没有做任何与GetWordContent
f结。
相关问题
- 1. 使用VBA将Access中的RTF文本复制到Word表格
- 2. C++将格式化的代码复制到Word中(如Visual Assistance)
- 3. word中的格式化html文本
- 4. VBA:将文本文件中的行复制到Word文档中
- 5. 将格式化文本复制到剪贴板
- 6. 如何将格式化文本复制到剪贴板
- 7. 从Access格式文本数据传输到Word
- 8. VBA从word doc中的表格复制文本到excel?
- 9. 从Word复制到textarea保持格式
- 10. Word VBA将突出显示的文本复制到新文档并保留格式化
- 11. VBA将Word中的多行文本复制到Excel单元格中
- 12. 将Word格式复制到Outlook邮件中
- 13. Mac上的Emacs:将Word 2008中的文本复制到Emacs
- 14. 将富文本格式字符串复制为格式文本
- 15. 如何使用.NET将Excel中格式化的单元格复制到Word表格单元格中?
- 16. java将Excel单元格内容复制到word文档中
- 17. 将格式化文本插入Word文档
- 18. 来自Access的数据将不会复制到Word书签
- 19. 将SQL从Access复制到Delphi脚本
- 20. 将格式化文本复制到剪贴板中,字体除外
- 21. 找到从Word到Excel文本后的文本复制
- 22. 将图片复制到word文档
- 23. VB:将Excel单元复制到Word并保留Excel格式
- 24. 在用户可以复制到word的WPF中显示一些格式化的文本
- 25. 将Qtablewidget复制到word
- 26. 从Json.Serde格式化表格复制到文本文件格式化蜂巢表格
- 27. 如何使用Lotusscript和/或VBA将格式化的Richtext复制到Word文档中?
- 28. 将HTML表格复制到Word文件 - 覆盖错误
- 29. 将ppt复制到格式化的Excel中
- 30. VBA word格式化
这是可能的,是的。你的问题到底是什么?用filepicker选择多个文件?调整代码以便每个文件执行一次?选择扩展名为.doc或.docx的文件夹中的所有文件? –
我想重复几个文件,而不是为每个文件重新运行它。我修改了AllowMultiSelect = True,但希望为所选的所有文件或特定文件夹中的所有文件(以最简单的文件为准)运行它。对不起,我对这一切都很陌生。谢谢。 – niawo