VBA(?)如何提取链接和插入的图像的文件名-Word 2013 [英] VBA(?) How to extract filename of images linked and inserted - Word 2013

查看:420
本文介绍了VBA(?)如何提取链接和插入的图像的文件名-Word 2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Word文档(.docx)中插入和链接图片(从文件.emf中插入图片).我们的文档和图形文件存储在我们的网络驱动器上.然后,我们将文档提供给作者进行处理.文档中的图片对作者很有用.

We insert and link pictures (insert picture from file .emf) in our Word documents (.docx). Our documents and the graphic files are stored on our network drives. We then provide our documents to the authors to be worked on. The pictures in the documents are useful for the authors.

如何以编程方式和全局方式(从文档角度考虑,而不是批处理文档):提取链接和插入的图片的文件名(不带文件扩展名)?

How do I programmatically and globally (document wise, not batch processing documents): Extract the filename (without the file extension) of the pictures linked and inserted?

我们有一个将Word文档.docx导出到.XML的工具.

We have a tool that exports the Word document .docx to .XML.

Ps:我在Google上搜索了可能的/潜在的VBA解决方案.到目前为止,我收集到了:

Ps: I googled for possible/potential VBA solutions. So far, I gather:

  1. 无法确定/检查图片是否已正确链接/正确插入.docx
  2. 无法查看源代码(至少我尝试过Alt + F9/Shift + F9)

还是要用macro/vba吗?

Or is macro/ vba not the way to go?

规格: Word 2013. 64位 图形格式.电动势 图形和Word文档存储在网络驱动器上 未通过INCLUDEPICTURE字段插入和链接图形.

Specs: Word 2013. 64 bit Graphic format. Emf Graphic and word documents store on a network drive Graphics not inserted and linked via the INCLUDEPICTURE field.

推荐答案

要获得类似浮动图片和内联图片的列表,可以使用以下代码:

To get a listing of floating and inline linked pictures alike, you might use code like:

Sub Demo()
Dim Shp As Shape, iShp As InlineShape, StrOut As String
With ActiveDocument.Range
  StrOut = "Linked Shapes:"
  For Each Shp In .ShapeRange
    With Shp
      If .Type = msoLinkedPicture Then
        StrOut = StrOut & Chr(11) & Split(.LinkFormat.SourceName, ".")(0)
      End If
    End With
  Next
  If InStr(StrOut, Chr(11)) = 0 Then StrOut = StrOut & " None."
  .InsertAfter vbCr & StrOut
  StrOut = "Linked InlineShapes:"
  For Each iShp In .InlineShapes
    With iShp
      If .Type = wdInlineShapeLinkedPicture Then
        StrOut = StrOut & Chr(11) & Split(.LinkFormat.SourceName, ".")(0)
      End If
    End With
  Next
  If InStr(StrOut, Chr(11)) = 0 Then StrOut = StrOut & " None."
  .InsertAfter vbCr & StrOut
End With
End Sub

请注意,以上代码仅搜索文档正文;而不是页眉,页脚等.列表在文档末尾输出.

Do note that the above code only searches the document body; not headers, footers, etc. The listings are output at the end of the document.

这篇关于VBA(?)如何提取链接和插入的图像的文件名-Word 2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆