所以我的宏的目标是采用这样排序的word文档:
<image>
<caption>
<image>
<caption>
并抓取文档并创建一个如下所示的新文档:
我目前的代码如下:
Sub tryinterleave2()
'
' tryinterleave2 Macro
'
'
Dim oField As Field
Dim oCurrentDoc As Document
Dim oNewDoc As Document
Dim sFileName As String
Dim sFigName As String
Dim ParaNum As Integer
Set oCurrentDoc = ActiveDocument
Set oNewDoc = Application.Documents.Add
For Each oField In oCurrentDoc.Fields
If oField.Type = wdFieldIncludePicture Then
sFileName = Replace(oField.Code, "INCLUDEPICTURE", "")
sFileName = Replace(sFileName, "MERGEFORMAT", "")
sFileName = Replace(sFileName, "\*", "")
sFileName = Replace(sFileName, "\d", "")
sFileName = Replace(sFileName, Chr(34), "")
sFileName = Replace(sFileName, "\\", "\")
sFileName = Trim(sFileName)
oNewDoc.Range.InsertAfter sFileName & vbCrLf
ElseIf oField.Type = wdFieldSequence Then
sFigName = oField.Result
oNewDoc.Range.InsertAfter sFigName & vbCrLf
End If
Next oField
oNewDoc.Activate
Set oField = Nothing
Set oCurrentDoc = Nothing
Set oNewDoc = Nothing
End Sub
我得到的图像位置很好....但我只能获得字幕序列字段的结果。所以没有得到“图1:春天”,我得到“1”。我今天刚刚开始搞乱VBA,所以答案可能很简单。任何帮助将不胜感激。
答案 0 :(得分:0)
我实际想出来了。对不完整的问题感到抱歉......我不知道发生了什么。但是,我设置了一个循环遍历每个段落的for循环,在其中我设置了另一个for循环,检查该段落中的任何字段。在里面我放入if / else确定了字段的种类并适当地导出到新的word文档。使用这种方法,我总是知道我所在的段落,因此不必依赖于字段对象和文档其余部分之间的任何关联(我不相信它)