Range could not be deleted

MTmace

Member
Joined
Feb 1, 2005
Messages
9
Programming Experience
Beginner
I am trying to open a word doc, make some changes where I have placed bookmarks and then save the document. I tried to follow the example found support.microsoft.com/default.aspx?scid=kb;EN-US;Q3316383 but get the following error.

This Range can not be deleted

I have confirmed that my book mark is getting recognized because I can read it in to the application. I also have the
Imports
Word
at the top of the appplication.
Can someone help me out? Below is my code.


Dim oWord As Word.Application
Dim oDoc As Word.Document

Dim strText As String
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = False


oDoc = oWord.Documents.Add("C:\text.doc")
strText = "Text Name"
Dim oRange As Range
If oDoc.Bookmarks.Exists("fldAddName") Then
oRange = oDoc.Bookmarks.Item("fldAddName").Range
oRange.Text = strText
End If

MTmace
 
Discovery

I think I discovered the solution. I was creating a bookmark on a field. If I added plain text, highlighted the text I wanted to change and created a bookmark on that text I was able to execute the code with no error.

MTmace
 
Back
Top