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 / January 2007

Tip: Looking for answers? Try searching our database.

Word Visual Studio Programming Problem.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aaron Tiainen - 28 Jan 2007 21:47 GMT
Hi All,

I have written the following code below which worked fine with Word 2003,
but fails with Word 2007.  Can anybody shed any light on it for me?

Dim wdApp As New Microsoft.Office.Interop.Word.Application
Dim objDoc As Microsoft.Office.Interop.Word.Document =
wdApp.Documents.Open(FileName:=FileToOpen.ToString)
Dim RS As ADODB.Recordset
Dim VarSQLGetDetails As String

RS = New ADODB.Recordset
'Make this application visible
wdApp.Visible = True
wdApp.Selection.Find.ClearFormatting()

With wdApp.Selection.Find
.Text = "<<MATTERNUMBER>>"
.Replacement.Text = Main.txbldmainmatternumber.Text
.MatchCase = False
End With

wdApp.Selection.Find.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)

With wdApp.Selection.Find
.Text = "<<PARALEGALLOGON>>"
.Replacement.Text = Main.cboldmainparalegal.Text
.MatchCase = False
End With

It always comes to a halt at the line .text="<<MATTERNUMBER>>".

Thanks.

Aaron.
Perry - 28 Jan 2007 21:54 GMT
What happens when you include .Wrap parameter of .Find
(as indicated in below sequence.)

With wdApp.Selection.Find
.Text = "<<PARALEGALLOGON>>"
'' include following line
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.WdFindContinue
.Replacement.Text = Main.cboldmainparalegal.Text
.MatchCase = False
End With

Krgrds,
Perry

> Hi All,
>
[quoted text clipped - 31 lines]
>
> Aaron.
Aaron Tiainen - 29 Jan 2007 00:56 GMT
Thanks Perry,

Same issue happens.  It actually stops on the first line still, so it isn't getting to the second line.  So now change.  Any other suggestions?

The actual error message is "External component has thrown an exception." and the err.description at that point is
"Conversion from type 'DBNull' to type 'Integer' is not valid."

Anymore suggestions would be appreciated.

Thanks.

Aaron.
perry - 30 Jan 2007 12:10 GMT
It works with Word 2k3, you stated.
What happens if you switch the Interop assembly in yr project references
from version 11.0.0.0 to 12.0.0.0?
Will this code work then?

Signature

Krgrds,
Perry

> Hi All,
>
[quoted text clipped - 31 lines]
>
> Aaron.
Aaron Tiainen - 30 Jan 2007 12:29 GMT
Yeah - 2003 is fine.  I remove the reference "microsoft word 11.0" and replaced with "microsoft word 12.0" and it errors straight away. (
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred)

I can't figure out what is going on with it.  I'm thinking about completely rewriting it to see if i can solve it.  I'd like it to work for both 2003 and 2007 versions of word, but i don't know how lucky i will be.

Any more ideas.. .I'm a bit of a novice by the way.

Thanks.

Aaron

> It works with Word 2k3, you stated.
> What happens if you switch the Interop assembly in yr project references
[quoted text clipped - 36 lines]
>>
>> Aaron.
Cindy M. - 31 Jan 2007 19:08 GMT
Hi Aaron,

> Yeah - 2003 is fine.  I remove the reference "microsoft
> word 11.0" and replaced with "microsoft word 12.0" and
[quoted text clipped - 6 lines]
> solve it.  I'd like it to work for both 2003 and 2007
> versions of word, but i don't know how lucky i will be.

How about this article?

http://support.microsoft.com/default.aspx?scid=kb;en-us;313
104

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Perry - 31 Jan 2007 19:28 GMT
Hmm, Cindy that's interesting...
Now translate that into VB.net ... hahaha

But, that really makes sense and I've stumbled accross other issues
with more less the same problem.
Indeed, optional parameters work slightly different in .NET

Good thinking !!

Chrs,
Perry

> Hi Aaron,
>
[quoted text clipped - 23 lines]
> follow question or reply in the newsgroup and not by e-mail
> :-)

Rate this thread:






 
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.