如何使用VBA从Word中提取嵌入式.txt文件

时间:2019-07-02 00:36:39

标签: vba ms-word

我正在尝试在Word中编写一些VBA代码,该代码可以提取Word文档中的嵌入式.txt文件并将其保存到指定的文件夹中。

我对VBA不太熟悉,我尝试修改此脚本,但未成功: 任何帮助表示赞赏!

Sub Extract()

Dim num As Integer
Dim AD As Document
Set AD = ActiveDocument

Dim numObjects As Integer
numObjects = AD.InlineShapes.Count

'MsgBox numObjects  ' prints "11"

For num = 1 To numObjects
    If AD.InlineShapes(num).Type = 1 Then
        'it's an embedded OLE type so open it.
        AD.InlineShapes(num).OLEFormat.Open
        AD.InlineShapes(num).OLEFormat.Object.SaveAs FileName:="C:\Users\Public\test.txt", FileFormat:=42


    End If
Next num

结束子

0 个答案:

没有答案