ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extracting text from embedded Word Object (https://www.excelbanter.com/excel-programming/373665-extracting-text-embedded-word-object.html)

Barb Reinhardt

Extracting text from embedded Word Object
 
We have an embedded word object within our workbook and would like to
programmatically extract the text within the object and paste it in a
predefined text box. How would we go about doing this?

Thanks

Helmut Weber[_2_]

Extracting text from embedded Word Object
 
Hi Barb,

like this:

Sub Test10000()

Dim oWrd As Word.Application
Dim rTmp As Word.Range
Dim s As String
Dim oWrk As Workbook
Dim oSht As Worksheet
Set oWrk = ActiveWorkbook
Set oSht = ActiveSheet
oSht.OLEObjects(1).Activate
Set oWrd = GetObject(, "Word.application")
Set rTmp = oWrd.ActiveDocument.Range
s = rTmp.text
oWrd.ActiveDocument.Close
'oWrd.Quit
oSht.OLEObjects("TextBox1").Object.Value = s
End Sub

Don't try to paste a 100 pages word doc with pictures! ;-)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com