Set Word Document Style

  • Thread starter Thread starter eholz1
  • Start date Start date
E

eholz1

Hello Group,

I am trying to set a doc style from an excel macro to a word document.
I can set the style with "in-line" code, but cannot set the style (get
an "object" does not exist error)
from a sub procedure. I can move down in the word doc from a sub
procedure but it seems I cannot set the style for a line (like "Header
3", etc) Below is the sub procedure - what am I missing? I pass the
doc object and the application object.

Sub SelectBookMarkPlace(wApp As Word.Application, nCount As Integer)
With wApp.Selection
.MoveDown Unit:=wdParagraph, Count:=nCount, Extend:=wdMove
'.Style = thisDoc.Styles("Header 3")
End With
End Sub

thanks,

eholz1
 
Untested.

It looks like ThisDoc isn't defined anywhere.

maybe ???

dim ThisDoc as object
set thisdoc = wApp.activedocument

And unless you have a reference set to MSWord, I think you'll have trouble with
those MSWord constants.

You may want to replace them with their values:

?wdParagraph
4
?wdMove
0
 
Check the Styles Collection Object in Word VBA Help. The collection exists
under the Document object. Likewise the Selection object exists only in a
document. If you set an object to your document as Dave suggested, you
should get better results.

Sub SelectBookMarkPlace(wApp As Word.Application, nCount As Integer)

dim ThisDoc as object
set thisdoc = wApp.activedocument
With ThisDoc.Selection
.MoveDown Unit:=wdParagraph, Count:=nCount, Extend:=wdMove
.Style = ThisDoc.Styles("Header 3")
End With
End Sub



Untested, but probably closer to actual.

Ed
 
Hello Ed,
I need new glasses! the style SHOULD BE "Heading 3" not Header 3!!!!

dumb one!!!

Thanks for the info
 

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

Back
Top