Interacting with another app

Creating a new word document
Set wrd = CreateObject("Word.Application")
wrd.Documents.Add
wrd.Visible = True

Setting the start up path
wrd.Options.DefaultFilePath(wdStartupPath) = "c:\user\"

Quitting word
wrd.Quit

Starting word from another app
Set wrd = CreateObject("Word.Application")

Create and launch another app from Word
Set myobject = CreateObject("Excel.Application")
MsgBox myobject.StartupPath
Set myobject = Nothing

Using DDE Channel to send data to another app, like excel:

Dim lngChannel As Long
lngChannel = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=lngChannel, Command:="[OPEN(" &; Chr(34) _
 &; "C:\NameOfExcelFile.xls" &; Chr(34) &; ")]
DDETerminate Channel:=lngChannel
lngChannel = DDEInitiate(App:="Excel", Topic:="NameOfExcelFile.xls")
'Go to row 1 column 1 and key in data
DDEPoke Channel:=lngChannel, Item:="R1C1", Data:="Words you are keying in"
DDETerminate Channel:=lngChannel

Using DDE Channel to get data from another app, like excel:
Dim lngChannel As Long
lngChannel = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=lngChannel, Command:="[OPEN(" &; Chr(34) _
 &; "C:\Documents\NameOfExcelFile.xls" &; Chr(34) &; ")]"
DDETerminate Channel:=lngChannel
lngChannel = DDEInitiate(App:="Excel", Topic:="NameOfExcelFile.xls")
'Get information from row 1 column 1
MsgBox DDERequest(Channel:=lngChannel, Item:="R1C1")
DDETerminateAll

Using DDE to create a new worksheet in Excel:
Dim lngChannel As Long

lngChannel = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=lngChannel, Command:="[New(1)]"
DDETerminate Channel:=lngChannel

Using DDE to run a macro in excel:
Dim lngChannel As Long

lngChannel = DDEInitiate(App:="Excel", Topic:="System")
DDEExecute Channel:=lngChannel, Command:="[Run(" &; Chr(34) &; _
 "NameofExcelFile.xls!NameOfMacro" &; Chr(34) &; ")]"
DDETerminate Channel:=lngChannel

Comments

Popular posts from this blog

Find and replace

Menus and toolbars

Formatting