--- In [email protected], David Smith <[EMAIL PROTECTED]> wrote:
>
> I've never found anything in the MS object model to be that obvious
either if that's any consolation.
>
> Dave
>
> "Wilson, Stephen" <[EMAIL PROTECTED]> wrote:
To anyone interested:
>
> var bm: OLEVariant;
>
> bm:= 1; WD1.Bookmarks.Item(bm).Select; where bm is a ref to the
Bookmarks index (initial 1)
>
> Should have seen it yesterday if I'd looked further than the end of
my nose!
>
> Regards
>
> Steve
>
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED]
> Behalf Of Wilson, Stephen
> Sent: 17 December 2007 12:03
> To: [email protected]
> Subject: [delphi-en] Word Automation
>
> Hi all
>
> I'm using Delphi 5 OLEServer TWordApplication and TWordDocument as
follows:
>
> WA1.Connect;
> WA1.Visible := True;
> Filename:= 'C:\HPB.dot';
>
>
WA1.Documents.Open(Filename,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
> WD1.ConnectTo(WA1.ActiveDocument);
> if WD1.Bookmarks.Exists('Diag') then
> begin
> st:= 19; nd:= 30;
> WD1.Range(st,nd).Select;
> WA1.Selection.TypeText('Test text');
> end;
>
> What I want to do is select the bookmarked text (bookmark id
='Diag'. In the above example I have selected it by hardcoding the
start and end of the range, but how can I do it by simply referring to
the existing bookmark? I checked out MSDN and found
>
> ActiveDocument.Bookmarks("temp").Select
>
> at
http://msdn2.microsoft.com/en-us/library/aa192170(office.10).aspx ,
but WA1.ActiveDocument.Bookmarks('Diag').Select (or
WD1.Bookmarks('Diag').Select) does not work.
>
> Thanks in advance for any help . . .
>
> Best wishes
>
> Steve
>
>
***************************************************************************
> This e-mail and any files transmitted with it are confidential. If
you are not the intended recipient, any reading, printing, storage,
disclosure, copying or any other action taken in respect of this
e-mail is prohibited and may be unlawful. If you are not the intended
recipient, please notify the sender immediately by using the reply
function and then permanently delete what you have received.
> Content of emails received by this Trust will be subject to
disclosure under the Freedom of Information Act 2000, subject to the
specified exemptions, including the Data Protection Act 1998 and
Caldicott Guardian principles.
> This footnote also confirms that, unless otherwise stated, this
email message has been swept by Sophos Anti-virus for the presence of
computer viruses.
>
***************************************************************************
>
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: [EMAIL PROTECTED]
> Yahoo! Groups Links
>
>
***************************************************************************
> This e-mail and any files transmitted with it are confidential. If
you are not the intended recipient, any reading, printing, storage,
disclosure, copying or any other action taken in respect of this
e-mail is prohibited and may be unlawful. If you are not the intended
recipient, please notify the sender immediately by using the reply
function and then permanently delete what you have received.
> Content of emails received by this Trust will be subject to
disclosure under the Freedom of Information Act 2000, subject to the
specified exemptions, including the Data Protection Act 1998 and
Caldicott Guardian principles.
> This footnote also confirms that, unless otherwise stated, this
email message has been swept by Sophos Anti-virus for the presence of
computer viruses.
>
***************************************************************************
>
>
>
>
>
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile.
Try it now.
>
> [Non-text portions of this message have been removed]
>
I have programmed for about 3 years in VBA
I had to reprogram a program from VBA to Delphi and that is not hard
to do. Except for BookMarks.
In Delphi, you need an OLEVariant to pass as the Bookmark you are
using. In VBA, you can work with Strings. This is as far as i know not
possible in Delphi. This is difficult to work with, but in complience
with the rest of VBA as far as i know it.
In VBA you have a type with the name of collection.
It works something like this.
dim oCol as collection
set oCol = New Collection.
call oCol.Add(<value>, [<Name>])
Where the Name part is unique.
Here comes the problem with VBA.
You can use something like this:
call oCall.Add("Value1", "A")
call oCall.Add("Value2", "B")
call oCall.Add("Value3", "C")
etc.
You get the picture :)
You can access oCol through:
oCol("A") or oCol(1)
BUT there is NO way to know what names are stored in the collection.
This is a flaw, if you ask me in VBA. But unfortunately, this is the
way it works.
If there is someone here who knows how to use strings for bookmarks i
would be really grateful, because using numbers is workable, thank you
for the solution, but not the way i would like to use it. If the
document is changed and a bookmark is added, the program won't work
like intended.
Again, the solution is a workable one and i for one am happy you told
us, but still :)
TIA.