Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Auto: Delete after bookmark deletes bookmark
Message
From
21/04/2008 10:40:21
 
 
To
19/04/2008 05:36:46
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01311800
Message ID:
01312072
Views:
18
Hi Cetin,

.Collapse() does not seem to help. It is really funny but this only happens if the bookmark is on the very first line of the document. All the others do not get deleted if I issue loSelection.Delete() after moving to the bookmark and extending the selection to the end of the line. I think I will have to change how this company does things with their templates - right now they insert a bookmark and then *after* the bookmark they put a label e.g. "Contract Number". So my code was to go to the bookmark "ContractNo", extend the selection to the end of the line, delete the bookmark and then insert the actual contract number from the data in the VFP table. But they did not want to see the bookmark removed from the document and unfortunately for the very first bookmark in the doc, it always gets removed - I think because it is a character position zero in the doc.

So I might have to get them to either a) not put "label names" beside their bookmarks (and thus I can eliminate the step of deleting to the end of the line) or b) put a space in between the bookmark and the label name and then I can go to the bookmark, move the insertion point 1 char to the right and then extend the selection to the end of the line and delete as before.

Any other ideas?

Albert

>>Hi all,
>>
>>More Word automation stuff: code loops through 3 bookmarks in a Word template and a) deletes all the text after the bookmark to the end of the line (it is just a label for "non-automation" use) and then b) inserts some data.
>>
>>Works mostly okay except for some reason the very 1st bookmark in the document gets deleted when I issued the Selection.Delete() (after extending the selection to the end of the line).
>>
>>I tried moving the selection 1 char to the right before extending it to the end of the line (so as to be "off" the bookmark) but this puts the insertion point a char 2 which is not correct.
>>
>>Bookmarks 2 and 3 work okay as somehow they are different.
>>
>>Ideas of a workaround?
>>
>>Albert
>
>Albert,
>Are you collapsing selection not to include bookmark? Check Selection.Collapse. ie:
>
>#include wdconstants.h
>#Define NL Chr(13)+Chr(10)
>*** set the LOCALEID to English
>nlLocaleId=Sys(3004)		&& Save local id
>=Sys(3006,1033)				&& We will be sending instructions in English
>
>Use employee		&& test table
>oWordDocument=Createobject("word.application")	&& Create word object
>With oWordDocument
>  .Documents.Add && Create a new doc
>  .Visible = .T.
>  .Activate
>  Scan
>    .Selection.TypeText('Employee Info Start.'+NL)
>    .Selection.TypeText(Transform(emp_id)+NL+First_Name-(' '+Last_Name)+NL)
>    .Selection.Collapse(wdCollapseEnd)
>    lnRangeStart = .Selection.Range.End && set range for notes text and bookmark
>    .Selection.TypeText(Nvl(notes,'')+NL+NL)
>    lnRangeEnd   = .Selection.Range.End
>    .Activedocument.Bookmarks.Add('b'+Padl(Recno(),2,'0'),.Activedocument.Range(lnRangeStart,lnRangeEnd))
>  Endscan
>
>  firstBmkName = .Activedocument.Bookmarks(1).Name
>  .Activedocument.Bookmarks(1).Select
>  Messagebox('first bookmark selected',4096,'',3000)
>
>  .Selection.Collapse(wdCollapseEnd)
>  .Selection.Expand( wdParagraph )
>
>  Messagebox('Deleting para after first bookmark',4096,'',3000)
>  .Selection.Delete
>  .Selection.TypeText( 'Para deleted' + NL )
>
>  If .Activedocument.Bookmarks.Exists(firstBmkName)
>    .Activedocument.Bookmarks(firstBmkName).Select
>    .Selection.Font.Color = 0xFF
>  Endif
>Endwith
>
>**** Set the LocaleId to the previous value
>=Sys(3006,Val(nlLocaleId))
>
>Cetin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform