Select a frame in word with a macro in excel

T

Trefor

I am trying to write a macro in Excel that will copy the text in a Word frame
to a cell in Excel. Can anyone give me some sample code?
 
N

Ness

Trefor,
You need to reference ms forms 2.0 object library and and microsoft Word
object library for this to work:-

Option Explicit

Dim objClipBoard(1) As New DataObject
Dim objWd As Word.Application
Dim objWdDoc As Word.Document

Sub test()

Set objWd = New Word.Application
objWd.Visible = True
Set objWdDoc = objWd.Documents.Open("c:\test.doc")

objWdDoc.Frames(1).Select 'index of 1 being first frame in document
objWdDoc.Frames(1).Range.Select

Dim strFrameContents As String
strFrameContents = objWd.Selection
objClipBoard(0).SetText strFrameContents
objClipBoard(0).PutInClipboard

objClipBoard(1).GetFromClipboard
Range("a1").Select
ActiveCell.Formula = objClipBoard(1).GetText

Set objWd = Nothing
Set objWdDoc = Nothing
End
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top