Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

run-time error 13 - Type mismatch (don't know why)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
justalostgrunt - 06 Nov 2007 21:54 GMT
Hi,

What worked six months ago seems to give a runtime error now.
Revisting a VBA routine as the project has come out of moth balls.

error 13 - type mismatch on the line:

Set bmrange = destdoc11.Bookmarks("section11").Range ' locate the bookmark

In the snippet of the whole routine,

If Dir(strAtt) = "" Then
MsgBox "File does not exist"
Else
Set srcDoc = Wordapp.Documents.Open(strAtt) 'attachment sheet
End If

'open the letter
Set destdoc11 = Wordapp.Documents.Open(strInputFileName) 'letter

Set bmrange = destdoc11.Bookmarks("section11").Range ' locate the bookmark

'create new section - add a page past the bookmark
destdoc11.Bookmarks("section11").Range.InsertBreak
Type:=wdSectionBreakNextPage

're-insert the bookmark as we have removed it by the section break
destdoc11.Bookmarks.Add "section11", bmrange
'copy the text and replace the bookmark
bmrange.FormattedText = srcDoc.Range.FormattedText
destdoc11.close (wdSaveChanges)

'close the Attachment sheet
srcDoc.close (wdDoNotSaveChanges)

I retraced my steps revisted posts from April and use of bookmarks on the
FAQ word site and I can't see what could cause this glitch.
Corrupt VBA or the bookmarks in the original letter?

Any ideas appreciated.

Regards
bill
NZ VBA Developer - 07 Nov 2007 01:15 GMT
Bill,

I'm assuming that at some point in your code you have declared "bmrange" as
a Range object, yes? And have you tried putting in some code to check to
ensure that the "section11" bookmark actually exists in "destdoc11"? These
are the only two reasons I can think of for a 'type mismatch' error, and the
first case seems the most likely. If you don't explicitly tell Word that
"bmrange" is a Range object (and don't use Option Explicit) it will create
"bmrange" as a Variant type variable, and you may not be able to load a Range
into it. If it's just a matter of not being able to find the bookmark I would
expect a 'member of collection does not exist' type error instead.
Signature

Cheers!

The Kiwi Koder

> Hi,
>
[quoted text clipped - 39 lines]
> Regards
> bill
justalostgrunt - 07 Nov 2007 01:58 GMT
Hi,
Yes bmrange is declared as a range and option explicit is the case for the
module behind this headache - so to speak.

I am automating from an access database - not sure now if thats a problem -
but it worked before so I have to discount that.

The bookmark is there as the first part is to mail merge some data. The
letter is saved.
Destdoc11 becomes the letter.
I've checked the letter that is produced first to find the bookmarks (there
are 11) and appear OK.

Write some code to check the bookmark - ummm.

Regards
Bill

> Bill,
>
[quoted text clipped - 51 lines]
> > Regards
> > bill
NZ VBA Developer - 07 Nov 2007 02:25 GMT
Well that blows that theory. <g>

Unfortunately, I'm not familiar enough with Access to determine if it's
playing a role, but as you say, it worked before...

As for checking for the existence of the bookmark, that's just a couple of
lines. Bookmarks support an 'Exists' method, so it's just a matter of:

If destdoc11.Bookmarks.Exists("section11") Then
  'do the stuff you want to do with the bookmark
Else
  'handle the error however you think it should be handled
End If

I'm afraid that exhausts my supply of suggestions, altho maybe as part of
the debugging process you might want to put something in after you check for
the existence of the bookmark that will let you confirm that the right
bookmark is being used, such as:

  MsgBox destdoc11.Bookmarks.("section11").Range.Text

I've also found that sometimes just working with the Bookmark Range object
causes problems, but the workarounds (selecting the Bookmark Range and then
working with the Selection Range object instead) are ugly and probably not
advisable.

If none of this helps, let's hope that somebody else has some ideas.
Signature

Cheers!
The Kiwi Koder

> Hi,
> Yes bmrange is declared as a range and option explicit is the case for the
[quoted text clipped - 69 lines]
> > > Regards
> > > bill
justalostgrunt - 07 Nov 2007 03:17 GMT
Hi,
Thanks,
Will place that snipet of code into the routine and see what transpires.

Read somewhere that word is unpredictable and what may work on one computer
may not work on another. Something to do wth defining a page, But a bookmark
is a bookmark - unpredicatable blitters.

Thanks for your help.

Best Regards
Bill

> Well that blows that theory. <g>
>
[quoted text clipped - 97 lines]
> > > > Regards
> > > > bill
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.