Controlling WORD from Excel

L

lestercrombie

The code works until I get to this line:
WrdApp.Selection.Find.Style = ActiveDocument.Styles("Heading 4,SCENE
HEADING")

where an error says that no document is open.

It is clearly open, as WORD has started and I can see the open document
on the screen.

I have added a reference to the WORD library. I've used early
binding.

Why is this error occurring??

My code is below:



Dim WrdApp As Word.Application
Dim WrdDoc As Word.Document
'*********************************

Sub ImportSceneHeadings()

'Input the Script Filename
Call GetScriptFilename
'Start WORD?
Set WrdApp = CreateObject("Word.Application")
WrdApp.Visible = True
'Open the MICROSOFT WORD DOCUMENT
Set WrdDoc = WrdApp.Documents.Open(ScriptFileName)

'Activate WORD document that has been opened. ie the script.
WrdDoc.Activate

'Initialize
EOF = False
j = 1
WrdApp.Selection.StartOf unit:=wdStory 'Move selection point to the
start of the script

'Do a FIND for Heading 4, SCENE HEADING
WrdApp.Selection.Find.ClearFormatting
WrdApp.Selection.Find.Style = ActiveDocument.Styles("Heading 4,SCENE
HEADING") '/

With WrdApp.Selection.Find
..Text = ""
..Replacement.Text = ""
..Forward = True
..Wrap = wdFindStop
..Format = True
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
..ParagraphFormat.Borders.Shadow = False
End With
 
D

Dave Peterson

Without testing...

What happens if you try:

WrdApp.Selection.Find.Style _
= wrdapp.ActiveDocument.Styles("Heading 4,SCENE HEADING")

(line wrap broke SCENE and HEADING on two lines. I'm not sure what really goes
there.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top