run-time error 13 - Type mismatch (don't know why)
by anVzdGFsb3N0Z3J1bnQ » Thu, 08 Nov 2007 06:54:01 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
RE: run-time error 13 - Type mismatch (don't know why)
by TlogVkJBIERldmVsb3Blcg » Thu, 08 Nov 2007 10:15:00 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.
--
Cheers!
The Kiwi Koder
RE: run-time error 13 - Type mismatch (don't know why)
by anVzdGFsb3N0Z3J1bnQ » Thu, 08 Nov 2007 10:58:00 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
RE: run-time error 13 - Type mismatch (don't know why)
by TlogVkJBIERldmVsb3Blcg » Thu, 08 Nov 2007 11:25:00 GMT
ell 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.
--
Cheers!
The Kiwi Koder
"justalostgrunt" wrote:
RE: run-time error 13 - Type mismatch (don't know why)
by anVzdGFsb3N0Z3J1bnQ » Thu, 08 Nov 2007 12:17:01 GMT
i,
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
"NZ VBA Developer" wrote:
Similar Threads:
1.Error: run-time error 13 Type mismatch
I get this error every time I close Word 2002. Anyone
know how to fix it?
2.Run-time error 13 - Type mismatch
I get the run-time error everytime I close a document in
Word 2002, otherwise everything works fine. I saw the
responses to others that have similar problems and tried
the "fixes". I have disabled the Norton office plug-in,
use Acrobat 5.0.5 and run Winfax 5.1 so they don't seem
to be the problem as Suzanne Barnhill kindly suggested (1-
20-04, 9:51pm). Any other ideas would be greatly
appreciated!
3.MS Word - Run-time error '13' : Type mismatch
When closing any MS Word document, I get a "Run-time
error '13': Type mismatch" message in a window
titled "Microsoft Visual Basic". The window only allows
me to select "end". I am using Office XP Professional. I
am a computer novice, so any help or guidance would be
really appreciated.
4.Run-time error '13' type mismatch on close
all of a sudden, every time I close word 2000, I get the
error Microsoft Visual Basic, 'run-time error '13' type
mismatch. I hit end and word closes. wondering what can
be done.
thanks,
Larry
5.Run-time error '13'" Type mismatch when I run my VBA procedure
I get a Run-time error '13'" Type mismatch, when I try to run a VBA macro
to use an email template to create an email, and send an attachment
When I click the debug button, the following line is highlighted:
Set objOutlookAttach = .Attachments.Add(strAttch01Nam)
Any insights or suggestions would be much appreciated.
Thanks,
Marceepoo
P.s. Here's the whole macro:
Sub CreateFromTemplate()
Dim myOlApp As Outlook.Application
Dim myItem As Outlook.MailItem
Dim strTemplatNam As String
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.MailItem
Dim strAttch01Nam As String
'
strTemplatNam = "C:\Documents and Settings\marxp\Application
Data\Microsoft\Templates\bcc_NM.oft"
strAttch01Nam = "E:\Archive.2005-04-21-00-30.rar.lst.txt"
'
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItemFromTemplate(strTemplatNam)
'
With myItem
' Add the To recipient(s) to the message. Substitute
' your names here.
'Set objOutlookRecip = .Recipients.Add(" XXXX@XXXXX.COM ")
' objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(strAttch01Nam) Then
Set objOutlookAttach = .Attachments.Add(strAttch01Nam)
End If
End With
'
myItem.Display
End Sub