Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Hi all,
When I applied the following code it shows the error 'Error HRESULT E_FAIL has been returned from a call to a COM component.

Dim oTemplate As Word.Template
      Dim tempt_fname As String = Application.StartupPath
      Dim oDoc As Word.Document
      oDoc = oWord.Documents.Add(tempt_fname + "//")

      oTemplate = oWord.ActiveDocument.AttachedTemplate()
      Dim rng As Word.Range = oWord.ActiveDocument.Tables(1).Rows(8).Cells(2).Tables(1).Rows(5).Cells(1).Range
        'rng.SetRange(Start:=rng.Start, [End]:=rng.End)
      oTemplate.AutoTextEntries("Question").Insert(Where:=rng, RichText:=True) 'after exicuting this line it is showing error

But when I apply the following code after placed the cursor inside the word doc it is working fine .But I need to create the location dynamically
oTemplate.AutoTextEntries("Question").Insert(Where:=oWord.Selection.Range, RichText:=True)

Pls Help me
Thanks & Regards,
Posted 9-Jul-12 3:35am
Edited 11-Jul-12 10:16am
(no name)130.2K
ryanb31 at 11-Jul-12 15:17pm
You likely need to call Activate on the ActiveDocument so that it actually has the focus.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 450
1 OriginalGriff 230
2 DamithSL 150
3 Dave Kreskowiak 110
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,740
1 DamithSL 5,644
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,011
4 Kornfeld Eliyahu Peter 4,539

Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 11 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100