Hi All,
I have a VB application which opens a word file to search for some text
strings.
At home there is no problem but when I try this code at work on a
win2000 machine with office
2000 installed it crashed somewhere at this line:
Do Until sFile = ""
sFileoud = sFile
Tekst1.Text = sFileoud
Tekst3.Text = ""
Me.Refresh
lCounter = lCounter + 1
Set olWordDocs = olApplication.Documents.Open(FileName:=oDisk + sFile,
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:=
_
wdOpenFormatAuto)
If olApplication.ActiveDocument.ProtectionType <>
wdNoProtection Then
olApplication.ActiveDocument.Unprotect
End If
olApplication.Selection.Find.ClearFormatting
With olApplication.Selection.Find
.Text = "MSGID"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
olApplication.Selection.Find.Execute
olApplication.Selection.MoveRight Unit:=wdCharacter,
Count:=3
olApplication.Selection.EndKey Unit:=wdLine,
Extend:=wdExtend
sRefnr = ""
sRefnr = olApplication.Selection
Does anyone know what is wrong here?
Regards
Marco
Kodeworks - 07 Feb 2006 22:21 GMT
Marco
Are you running a more recent version of Word on the home computer? If
you are, then it's likely your application is failing on
Set olWordDocs = olApplication.Documents.Open .............
To fix this you need to use late binding if you want to continue to
develop on your home computer. If you develop your code on the work
computer, then it will probably run fine on your home computer. You'll
find an explanation of the how's and why's here
http://support.microsoft.com/default.aspx?scid=kb;en-us;245115
Sunil Jadwani
Kodeworks - Business Automation Solutions
www.kodeworks.com
Jezebel - 07 Feb 2006 23:07 GMT
If you switch to late binding, you'll also need to deal with all those Word
constants (wdCharacter, wdFindContinue, etc) which will no longer be
defined.
> Marco
>
[quoted text clipped - 12 lines]
> Kodeworks - Business Automation Solutions
> www.kodeworks.com
Ed - 08 Feb 2006 20:59 GMT
Pardon me for jumping in - but once you do pick up the object and bind to
Word, don't the constants get their definition? Maybe I've just been lucky
so far, but I've not had any problems writing in early binding to use the
IntlliSense and then switching to late binding to run. Such as (code
snipped to relevant bits):
Dim WD As Object
On Error Resume Next
Set WD = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WD = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0
WD.Documents.Open doc
WD.Visible = True
WD.Documents(doc).Windows(1).View.Type = wdPrintView
Ed
> If you switch to late binding, you'll also need to deal with all those Word
> constants (wdCharacter, wdFindContinue, etc) which will no longer be
[quoted text clipped - 16 lines]
> > Kodeworks - Business Automation Solutions
> > www.kodeworks.com
vonclausowitz@gmail.com - 08 Feb 2006 12:07 GMT
You mean defining variables as objects?
Like this:
Dim olApplication As Object
Dim olWordDocs As Object
Marco
Kodeworks schreef:
> Marco
>
[quoted text clipped - 12 lines]
> Kodeworks - Business Automation Solutions
> www.kodeworks.com
Jezebel - 08 Feb 2006 19:55 GMT
Late binding means you remove the reference to Word from the project
references, and instead use
Dim olApplication as Object
Set olApplication = CreateObject("Word.Application")
The problem you might be having at the moment is that your app is compiled
to run with one version of Word (Word 10 or 11, whatever it shows as the
library reference) and fails on a computer that has a different library.
> You mean defining variables as objects?
> Like this:
[quoted text clipped - 22 lines]
>> Kodeworks - Business Automation Solutions
>> www.kodeworks.com
vonclausowitz@gmail.com - 08 Feb 2006 20:02 GMT
How can that be solved?
Exept of course doing the programming on the other machine.
Marco
Jezebel - 08 Feb 2006 22:02 GMT
By using late binding, as described. Late binding uses whatever version of
the library is actually available on the machine. You have to write your
code using the earliest version that you want to support; and to be thorough
you should also check the version when you first instantiate the object, and
exit if it's a version the app doesn't support.
> How can that be solved?
> Exept of course doing the programming on the other machine.
>
> Marco