简体   繁体   中英

Copy and Paste active Word document to active Excel document using VBA

Is it possible to copy the contents of a word document (Which is open) into an active excel document by using VBA ?

I am using excel / word 2013

Hi i found the solution to my own question.

In the Excel workbook you must set up the following

'Tools -> References -> Microsoft Forms 2.0 Object Library' , or you will get a "Compile error: user-defined type not defined"

       Sub ClipboardToExcel()

       Dim MyData As DataObject
       Dim strClip As String


       Set MyData = New DataObject
       MyData.GetFromClipboard
       strClip = MyData.GetText

       Sheets("sheet2").Select
       Range("A1").Select
       ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= 
       _
       False, NoHTMLFormatting:=True

      End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM