Click here to Skip to main content
12,630,967 members (32,980 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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 + "//BEC06_CTDR_ICE_Doc.dot")
 

      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.Select()
        '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,
Soumya
Posted 9-Jul-12 3:35am
soumyaraj1.3K
Updated 11-Jul-12 10:16am
RyanDev229.4K
v2
Comments
ryanb31 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 11 Jul 2012
Copyright © CodeProject, 1999-2016
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