Board index » delphi » WORD 8 and OLE - I AM SO CONFUSED

WORD 8 and OLE - I AM SO CONFUSED

I am writing an application to manage Word 8 (97) documents from Delphi.
(Login my database on the net, search for a document, different rights
and access to docs for user and group, open doc if not used by another
person and user has the rights, calling word withe ole to open the doc
and piping passwords etc. )

The problem is that word will not accept my OLE stuff.
In fact the problem is that i am just beginning programming with DELPHI.
WORD will get the OLE calls, but perhaps i do it in a wrong syntax.

I waste a lot of money and time trying to get information over the WWW,
IRC, BORLAN up and running helpline ( 3,60 DM per minute !), several
books , and many people who alleged know everything about OLE and
DELPHI. Nobody was able to give me further information about my problems
with WORD 8 OLE and DELPHI !

Hint from a BORLAND Q&A was to open WORD8.OLB in DELPHI !
Wow - a lot of stuff in a new .pas - file .But what will i do now ???

What is the difference between Word.Application.wordbasic and Word.basic
?
Some calls works fine others dont.

                 I AM SO CONFUSED !

 ( I thought about programming in VB ! You see i am CONFUSED )

I want to open word like this because i am able to control if word is
still running:

CreateProcess(nil,pchar....
GetExitCodeProcess(ProcessInformation....
  if (Code<>Still_Active) then begin ...

how can i be shure that the OLE-Object i am sending calls over is
identical with the process i created ? In other words i want to be shure
that the word-task i just started is the word-task
i am using as an OLE-server.

App := GetActiveOleObject ('Word.Application') did not work.

And if it works how to identify what and how many instances of word are
running ?

Here is a part of the source from my projekt :

procedure TForm1.Button3Click(Sender: TObject);

// uses ComObj;

var
    App: Variant;
    Doc: Variant;
    Obj: Variant;
    w_var:Variant;
begin

try
    App := CreateOleObject ('Word.Application');

except
    MessageDlg('Can not open WORD !',mtError, [mbOk], 0);
end;

App.Visible := True;

try
  App.Documents.Open('d:\daten\XXX.doc');
except
    MessageDlg('Can not open Document !',mtError, [mbOk], 0);
    Halt;
end;

Application.ProcessMessages;
Doc := App.ActiveDocument;
________________________________________________________________
At this point i want to :

        go to my doc header
                 in Word = ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
        search for a bookmark name A
                 in Word = Selection.GoTo What:=wdGoToBookmark, Name:="A"
        mark the text standing right
                 in Word = Selection.MoveRight Unit:=wdWord, Count:=1,
Extend:=wdExtend
        overwright it with my new text
                 in Word = Selection.TypeText Text:="Testtext"
                 in Delphi : App.wordbasic.Insert('some Text here');
        go to some other bookmarks and do the same
        protect the document with ProtectedForForms mode
                ActiveDocument.Sections(1).ProtectedForForms = True
                ActiveDocument.Sections(2).ProtectedForForms = False
                ActiveDocument.protect Password:="XXX", NoReset:=False, Type:=
                wdAllowOnlyFormFields

        save it under the same ( or different name )

// Here is a part of VBA-code i want to translate to DELPHI

Sub Macro1()
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow.
_
        ActivePane.View.Type = wdOutlineView Or
ActiveWindow.ActivePane.View.Type _
         = wdMasterView Then
        ActiveWindow.ActivePane.View.Type = wdPageView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.GoTo What:=wdGoToBookmark, Name:="A"
    With ActiveDocument.Bookmarks
        .DefaultSorting = wdSortByName
        .ShowHidden = True
    End With
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Selection.TypeText Text:="Testtext"
End Sub

Sub Macro2()
    ActiveDocument.Sections(1).ProtectedForForms = True
    ActiveDocument.Sections(2).ProtectedForForms = False
    ActiveDocument.Sections(3).ProtectedForForms = True
    ActiveDocument.protect Password:="XXX", NoReset:=False, Type:=
wdAllowOnlyFormFields
End Sub

//________________________________________________________________

A lot of Questions.

If you just can answer one of questions or give me any tip or hint you
would help me a lot !

Thank you for reading this and maybe wasting your time.

Christoph Kastl

e-Mail                                  phone
christoph.ka...@sector27.de     02362 91672

btw. Word was not an by wishlist but i have to do it this way (
Document-Managment software for Quality-Management with WORD 97 and a
some databases where all informations are stored in.)

This is my first message in a news goup - so forgive me for everything

 

Re:WORD 8 and OLE - I AM SO CONFUSED


Hi,
Take a look at Charlie Calvert article
<http://members.aol.com/charliecal/index.html>
named OLE automation Delphi,Word...

It's simply Great...    Cheers          

Christoph Kastl <christoph.ka...@sector27.de> wrote in article
<34931487.3...@sector27.de>...

Quote
> I am writing an application to manage Word 8 (97) documents from Delphi.
> (Login my database on the net, search for a document, different rights
> and access to docs for user and group, open doc if not used by another
> person and user has the rights, calling word withe ole to open the doc
> and piping passwords etc. )
> ......

> A lot of Questions.

> If you just can answer one of questions or give me any tip or hint you
> would help me a lot !

> Thank you for reading this and maybe wasting your time.

> Christoph Kastl

> e-Mail                                     phone
> christoph.ka...@sector27.de        02362 91672

Re:WORD 8 and OLE - I AM SO CONFUSED


Christoph,

Did you take a look at the Mail Merge program that I built? It doesn't
answer a lot of your questions but it is a start.

Also, are you using the Word VBA Help that came with Office 97? If you
haven't installed it with Office, I'm sure that you can find it on the
CD. The filename is "VBAWRD8.HLP".

Also, the entire VBA Programmer's Guides are on Microsoft's web site. Do
a search there for VBA and I'm sure you'll come up with it.

The WORD8.OLB file is a Type Library (or renamed Object Library), and it
is used to perform Early binding to Word objects. It is much faster to
program with as you don't have to map Variants. I haven't used the
WORD8.OLB file in my Mail Merge project, but it wouldn't be that hard to
change it.

Word of warning, once the Word OLB file has been mapped into Pascal,
edit the pascal file and change all types of Application to
_Application, or WordApplication, or whatever. If you don't you will
have interesting compile errors as Delphi tries to map the TApplication
object type from the Word Application object.

Anyway, once you get into the click with VBA, Type Libraries, and so on,
you will be churning out programs left and right. I'm not professing to
be a VBA or OLE expert with Delphi, as there are people here more attune
to this than I, but just letting you know some of my findings.

Good luck.

--
Brian Armstrong,
http://www.zba.com

Other Threads