Filling a Word Table gives run time error 'Type mismatch'

A

Aquarius

Hi,

I am having trouble filling a Word table with (predefined) texts, using
VBA.
Word XP

My table is contained in a Bookmark.
On the basis of a language-switch I want to fill the table with either
English, Dutch, German etc. predefined texts.
Plus with some info I have read from the Word doc (Title, number of
pages, etc.).

I use two (Private) Subs:
* langFillRapStat and
* FillTable
Both take a input-variable (aTable as Table)

Strange thing is that (at execution) WordVBA throws a 'run-time err 13:
Type mismatch' at me,
because of langFillRapStat; whereas it does not complain about
FillTable.

Sniplet of code is below.

Any ideas, help is appreciated.

Regards,
Aquarius


Public Sub theCallingRoutine(bLangHasChanged As Boolean)

sBookmark="myTable"

With ActiveDocument.Bookmarks(sBookmark).Range
Set tblRapStat = .Tables(1)
If bLangHasChanged Then

'fill table with language-dependant fixed texts
langFillRapStat tblRapStat
End If

'fill tabel with variable texts
FillTable tblRapStat
Set tblRapStat = Nothing
End With 'ActiveDocument.Bookmarks(sBookmark).Range

<more code here>

End Sub 'theCallingRoutine

Private Sub langFillRapStat(aTable As Table)
'Fills the DocStatus-table with fixed texts

<my code here>

End Sub 'langFillRapStat

Public Sub FillTable(aTable As Table)

<my code here>

End Sub 'FillTable
 
A

Aquarius

Jonathan,

Thank you for your reply, but problem is...
Well: I need to explain what my application is.

My application is our scientific/technical Report. Template is called:
Report.dot
Report.dot contains Bookmarks, Styles, Header/Footers and the like.

But usrForms, Toolbars, VBA-code etc. are contained in a template
called ReportCode.dot
I have a Reference in Report.dot to ReportCode.dot
This way we separate the contents of 'Report.doc' from VBA that
operates on that contents.
(If our writers send their 'Report.doc' to a Client: they don't send
our toolbars and code)

Problem is: I cannot 'step through' the ReportCode-code.
"Debug.Assert False" also doesn't work.
So I need a lot of MsgBoxes to find out what is going on.

And in one of the 'debug-lines' I had:
MsgBox modReportLib.LanguageNr, "langFillRapStat"
It took me a whole day to find out ONE COMMA was missing in that line

MsgBox modReportLib.LanguageNr, , "langFillRapStat"
and my "problem" was over.
Argh.....

Regards,
peter
Jonathan West schreef:
 
A

Aquarius

Jonathan,

Thank you for your reply, but problem is...
Well: I need to explain what my application is.

My application is our scientific/technical Report. Template is called:
Report.dot
Report.dot contains Bookmarks, Styles, Header/Footers and the like.

But usrForms, Toolbars, VBA-code etc. are contained in a template
called ReportCode.dot
I have a Reference in Report.dot to ReportCode.dot
This way we separate the contents of 'Report.doc' from VBA that
operates on that contents.
(If our writers send their 'Report.doc' to a Client: they don't send
our toolbars and code)

Problem is: I cannot 'step through' the ReportCode-code.
"Debug.Assert False" also doesn't work.
So I need a lot of MsgBoxes to find out what is going on.

And in one of the 'debug-lines' I had:
MsgBox modReportLib.LanguageNr, "langFillRapStat"
It took me a whole day to find out ONE COMMA was missing in that line

MsgBox modReportLib.LanguageNr, , "langFillRapStat"
and my "problem" was over.
Argh.....

Regards,
peter


Jonathan West schreef:
 
J

Jonathan West

Aquarius said:
Jonathan,

Thank you for your reply, but problem is...
Well: I need to explain what my application is.

My application is our scientific/technical Report. Template is called:
Report.dot
Report.dot contains Bookmarks, Styles, Header/Footers and the like.

But usrForms, Toolbars, VBA-code etc. are contained in a template
called ReportCode.dot
I have a Reference in Report.dot to ReportCode.dot
This way we separate the contents of 'Report.doc' from VBA that
operates on that contents.
(If our writers send their 'Report.doc' to a Client: they don't send
our toolbars and code)

There is no need for this separation. If you put both the styles and the VBA
in Report.dot, any documents created from it do not contain the VBA code ot
the toolbars.

Problem is: I cannot 'step through' the ReportCode-code.

Yes you can.

Make sure that you have ReportCode.dot open in an editing window, and open
its VBA project in the VBA editor. Put a breakpoint at the start of a
routine called from Report.dot. Run the routine by clicking the appropriate
toolbar button. The code will stop at the breakpoint and you can step on
from there.
"Debug.Assert False" also doesn't work.
So I need a lot of MsgBoxes to find out what is going on.

And in one of the 'debug-lines' I had:
MsgBox modReportLib.LanguageNr, "langFillRapStat"
It took me a whole day to find out ONE COMMA was missing in that line

MsgBox modReportLib.LanguageNr, , "langFillRapStat"
and my "problem" was over.
Argh.....

Use named arguments rather than blanks in an argument list. That line of
code would not have failed (even without the extra comma) had you written it
like this

MsgBox Prompt:=modReportLib.LanguageNr, Title:="langFillRapStat"

So, I'll repeat my earlier question. When you step through the code, which
line triggers the error?

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
A

Aquarius

Jonathan,

thank you for your reply and the advice you have given me.
Especially the idea to use named arguments in an argument list I will
take to heart.

The 'runtime error', that I thought was caused by passing parameters to
a Sub, was actually caused by the missing comma. The (faulty) debug
MsgBox triggered the Runtime error.

Thanks for your thoughts
(and: apologies for my double reply #3 and #5: I was too impatient).

regards,
peter

Jonathan West schreef:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top