wdPasteText粘贴在Word上的图像

我非常接近终于完成这个代码,我一直在努力,但我已经遇到了一些障碍。 我需要将所选内容作为纯文本粘贴到Word文档中,但是,使用当前代码将所选内容粘贴为图像。

Sub CopyRangeToWord() Dim objWord Dim objDoc Set objWord = CreateObject("Word.Application") Set objDoc = objWord.Documents.Add Sheets("Executive Outline").Range("B5:B220").Select Selection.Copy With objWord .Selection.PasteSpecial Link:=False, DataType:=wdPasteText, _ Placement:=wdInLine, DisplayAsIcon:=False End With objWord.Visible = True End Sub 

有人能让我知道我要去哪里吗? 我将不胜感激。

这里的解决scheme是使用这个代码:

 .Selection.PasteSpecial Link:=False, DataType:=2, _ Placement:=wdInLine, DisplayAsIcon:=False 

简短的解释…:

您正在使用Late Bindings,没有Option Explicit语句。 因此,像wdPasteTextwdInLine这样的所有MS Word constants都被认为是没有声明值的variables。 因此,你有两个常量。 解决scheme:

  1. 使用early binding来保持text constants
  2. 总是使用Option Explicit来避免这样的问题
  3. 对于late binding总是使用数值而不是文本常量。