ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   activate a Word Window from Excel VBA (https://www.excelbanter.com/excel-programming/323448-activate-word-window-excel-vba.html)

Ben

activate a Word Window from Excel VBA
 
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"

Ben

activate a Word Window from Excel VBA
 
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

"ben" wrote:

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"



All times are GMT +1. The time now is 12:36 PM.

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