activate a Word Window from Excel VBA

B

ben

I have a lot of cell data from excell I am Transfering to a Word document
that will be manually opened, I want to know how to switch from excel to
having the Word document the Active window so that I can perform the sendkeys
statement to that window.

Sub saywhat()
On erorr GoTo yui
Application.Interactive = False
Application.Windows("file.doc").Activate
For m = 2 To Sheet1.UsedRange.Rows.Count
Cells(m, 4).Value = Application.WorksheetFunction.Proper(Cells(m, 4).Value)
stfw = " " + Cells(m, 2).Value + ", " + Cells(m, 3).Value + _
Chr$(13) + Left(Cells(m, 1).Value, 2) _
+ " " + Cells(m, 4).Value + Chr$(9)
If m / 2 = Int(m / 2) Then stfw = stfw + Chr$(9)
SendKeys stfw, Wait:=True
Next
yui:
Application.Interactive = True
End Sub


that is the code in it's entirety, it will send the keys all right but i
need it to send it to the Word Doc "files.doc"
 
B

ben

I always seem to find the answer before someone helps me. haha here is the
ammended code

Sub saywhat()
On erorr GoTo yui
channelNumber = Application.DDEInitiate( _
app:="WinWord", _
topic:="C:\files.doc")
Application.DDEExecute channelNumber, "[ACTIVATE ""files.doc""]"
For m = 2 To Sheet1.UsedRange.Rows.Count
Cells(m, 4).Value = Application.WorksheetFunction.Proper(Cells(m, 4).Value)
stfw = " " + Cells(m, 2).Value + ", " + Cells(m, 3).Value + _
Chr$(13) + Left(Cells(m, 1).Value, 2) _
+ " " + Cells(m, 4).Value + Chr$(9)
If m / 2 = Int(m / 2) Then stfw = stfw + Chr$(9)
SendKeys stfw, Wait:=True
Next
DDETerminate 3
yui:
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