LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel macro to control Word Problem

I am trying to write an Excel macro which will eventually perform a sor
of mail merge via Word. In theory this should be v.v. easy but I a
running into some basic trouble. More than likely it is my very limite
VBA knowledge.

Initially to get started I wrote a macro in Excel to copy a value fro
an Excel cell into a Word document using paste special. This wa
succesful. I then tried to get my Excel macro to find/replace som
values on a word document and it was then I ran into trouble. My macr
is below. Can someone recommend a good book which has more focus o
running one office package macro on another. I have never had an
trouble writing macros while staying in the same app.

Cheers,

Dave


Sub ControlWord()
' I have picked Microsoft Word from ToolsReferences
' in the VB editor to execute Word commands.
' I read VB Help topic "Controlling One Microsoft Office Applicatio
from Another"

Dim appWD As Word.Application
' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application")
appWD.Visible = True

Sheets("Data").Select
' Copy the data for the new document to the clipboard
Range("A1").Copy
' Tell Word to create a new document
appWD.Documents.Add
' Tell Word to paste the contents of the clipboard into the ne
document
appWD.Selection.PasteSpecial Link:=False
DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False

appWD.Selection.WholeStory
'This is the problem part from here on I get Debug error 5
appWD.Selection.Find.Text = "Ping"
appWD.Selection.Find.Replacement.Text = "Pong"
appWD.Selection.Find.Forward = True
appWD.Selection.Find.Wrap = wdFindContinue
appWD.Selection.Find.Format = False
appWD.Selection.Find.MatchCase = False
appWD.Selection.Find.MatchWholeWord = False
appWD.Selection.Find.MatchWildcards = False
appWD.Selection.Find.MatchSoundsLike = False
appWD.Selection.Find.MatchAllWordForms = False
appWD.Selection.Find.Execute Replace:=wdReplaceAll
' Close the Word application
appWD.Quit
End Su

--
Message posted from http://www.ExcelForum.com

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set Focus Problem for textbox control on multipage control ExcelDeveloperSPR Excel Programming 1 July 16th 04 08:54 PM
Word Control in Excel Stuart[_5_] Excel Programming 10 July 11th 04 08:47 PM
how to control word from excel Torstein S. Johnsen[_2_] Excel Programming 1 February 10th 04 02:10 PM
Print Control in Word/Excel Charles Maxson Excel Programming 0 December 30th 03 08:55 PM
Print Control in Word/Excel losmac[_2_] Excel Programming 0 December 30th 03 08:22 PM


All times are GMT +1. The time now is 03:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"