简体   繁体   English

将 Word 文档中的图像复制到 Excel 单元格中

[英]Copy an image from a Word document into an Excel cell

I want to copy a picture from a word document into a cell in Excel, but every time I try to paste the picture I get an "\".我想将word文档中的图片复制到Excel的单元格中,但是每次我尝试粘贴图片时都会得到一个“\”。

Can someone help me please?有人能帮助我吗?

Is there a simple way to do this operation in VBA?在 VBA 中是否有简单的方法来执行此操作?

I use selection to search between two chapters (The selection works perfectly but the copy does not.)我使用选择在两章之间搜索(选择完美,但副本没有。)

My code is as follows:我的代码如下:

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\test.docx")
Dim r1 As Long


wrdApp.Selection.WholeStory
wrdApp.Selection.Find.ClearFormatting
With wrdApp.Selection.Find
     .Text = "ABCD"
     .Forward = True
     .Wrap = wdFindContinue
     .Format = False
     .MatchCase = False
     .MatchWholeWord = True
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
     .Execute
End With
r1 = wrdApp.Selection.Range.End

wrdApp.Selection.Find.Text = "BCDE"
If wrdApp.Selection.Find.Execute Then
    wrdApp.Selection.Collapse wdCollapseStart
Else
    wrdApp.Selection.WholeStory
    wrdApp.Selection.Collapse wdCollapseEnd
End If
     
wrdDoc.Range(r1, wrdApp.Selection.Start).Select

With wrdApp.Selection
    MySheet.Range("B3").Value = .InlineShapes(1)
End With

There are several problems with your code.您的代码有几个问题。

  1. The variable MySheet isn't declared and doesn't point to anything.变量MySheet没有声明,也没有指向任何东西。 As a result your code doesn't compile.因此,您的代码无法编译。

  2. Although your question mentions using copy and paste your code doesn't copy or paste anything.尽管您的问题提到使用复制和粘贴,但您的代码不会复制或粘贴任何内容。

  3. The .Value of a cell cannot be a picture.单元格的.Value不能是图片。

  4. When using VBA, whether in Excel, PowerPoint or Word, it is best to avoid using the Selection object and use Range instead.在使用 VBA 时,无论是在 Excel、PowerPoint 还是 Word 中,最好避免使用Selection object,而是使用Range

     Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Set wrdApp = CreateObject("Word.Application") wrdApp.Visible = True Set wrdDoc = wrdApp.Documents.Open("C:\test.docx") Dim r1 As Word.Range Set r1 = ActiveDocument.Range With wrdDoc.Range With.Find.ClearFormatting.Replacement.ClearFormatting.Text = "ABCD".Format = False.Forward = True.Wrap = wdFindStop.MatchWildcards = False End With If.Find.Execute Then r1.Start =.End.Find.Text = "BCDE" If.Find.Execute Then r1.End =.Start End With r1.InlineShapes(1).Range.Copy ThisWorkbook.Sheets(1).Range("B3").PasteSpecial wrdDoc.Close False wrdApp.Quit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将文本从Excel中的范围复制到Word文档 - Copy Text from Range in Excel into Word Document 将值从Excel单元格插入到Word文档 - Insert a value from Excel cell to Word document 将单元格数据从excel复制到word VBA - Copy Cell data from excel to word VBA 如何将excel中单个单元格的超链接复制到由VBA aleady创建和填充的word文档? - How to copy a hyperlink from a single cell in excel to a word document which is being created and populated by VBA aleady? 如何将excel嵌入式图像复制到特定单元格表中的单词标题? - How to copy excel embedded image to word header in table in specific cell? 从 Excel 工作簿复制到 Word 文档而不添加引用 - Copy from Excel Workbook to Document from Word without Adding Reference 在打开的 Word 文档中查找未知姓名和姓氏,将其复制并粘贴到 excel .activesheet 中的单元格 A12 中,并使用 excel VBA - Find unknown name and surname in opened Word document, copy it and paste into the cell A12 in excel .activesheet with excel VBA 使用相对路径从Excel单元格创建指向Word文档的链接 - Create a link to a Word document from an Excel cell using a relative path 将嵌入式Excel工作表中的单元格值链接到Word 2013文档中 - Link cell values from embedded excel sheet into word 2013 document 将数据从指定的Excel文件复制到Word文档 - Copy data from specified excel file to word document
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM