+ Reply to Thread
Results 1 to 2 of 2

activate a Word Window from Excel VBA

  1. #1
    ben
    Guest

    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"

  2. #2
    ben
    Guest

    RE: 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"


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1