Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Set Focus Problem for textbox control on multipage control | Excel Programming | |||
Word Control in Excel | Excel Programming | |||
how to control word from excel | Excel Programming | |||
Print Control in Word/Excel | Excel Programming | |||
Print Control in Word/Excel | Excel Programming |