Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 4 Sep 2008 04:28:01 -0700,    group: microsoft.public.word.vba.general        back       


Inserting autotext entry   
I am trying to create a Word document from an Excel macro. 

Sub create_doc()
    Dim wordApp As Word.Application
    Set wordApp = CreateObject("word.application")
    With wordApp
        .documents.Add ("P:\word\proj.dot")
        .Selection.GoTo what:=wdGoToBookmark, Name:="pol_type"
        .Selection.TypeText Worksheets("New_Input").Range("h4")
        If Worksheets("New_Input").Range("h4") = "Rebate" Then
            .Selection.GoTo what:=wdGoToBookmark, Name:="death"
            .ActiveDocument.AttachedTemplate.AutoTextEntries("Death 
Benefits:").Insert _
        Where:=Selection.Range
        End If
.ActiveDocument.SaveAs "P:\word\test.doc"
        .Quit
    End With
    Set wordApp = Nothing
End Sub

The macro crashes on the line where it tries to insert the autotext. Any 
ideas what I have done wrong? I got the syntax via recording the macro in 
Word. 

Thanks,

Eric
date: Thu, 4 Sep 2008 04:28:01 -0700   author:   EricK

RE: Inserting autotext entry   
"EricK" wrote:

> I am trying to create a Word document from an Excel macro. 
> 
> Sub create_doc()
>     Dim wordApp As Word.Application
>     Set wordApp = CreateObject("word.application")
>     With wordApp
>         .documents.Add ("P:\word\proj.dot")
>         .Selection.GoTo what:=wdGoToBookmark, Name:="pol_type"
>         .Selection.TypeText Worksheets("New_Input").Range("h4")
>         If Worksheets("New_Input").Range("h4") = "Rebate" Then
>             .Selection.GoTo what:=wdGoToBookmark, Name:="death"
>             .ActiveDocument.AttachedTemplate.AutoTextEntries("Death 
> Benefits:").Insert _
>         Where:=Selection.Range
>         End If
> .ActiveDocument.SaveAs "P:\word\test.doc"
>         .Quit
>     End With
>     Set wordApp = Nothing
> End Sub
> 
> The macro crashes on the line where it tries to insert the autotext. Any 
> ideas what I have done wrong? I got the syntax via recording the macro in 
> Word. 

What do yo mean by "crashes"?
Any error message?
Does Word freeze?

What is actually selected by "Selection.range" when the code gets there?
Which template is used to store the AutoText entries? (Is it "proj.dot"?)

You mentionned the macro recorder, you may find the following page 
interesting and useful:
   http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm
date: Thu, 4 Sep 2008 10:31:03 -0700   author:   Jean-Guy Marcil

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us