Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OLE Automation & MS Word
Message
From
25/06/2003 13:34:53
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
25/06/2003 13:17:22
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00803546
Message ID:
00803895
Views:
9
>I get an OLE error 'Unknown Name' using your example
>
>This is the code I am using:
>
>oWordObj=CREATEOBJECT("Word.Basic")
>
>oWordObj.FileOpen (gcFormsPath + "Enrollment Form - client.doc")
>
>oWordObj.EditGoto ("NAME")
>oWordObj.Insert ("ken")
>
>with oWordObj
> .ActiveDocument.Bookmarks('BOOKMARK').Select
> .Selection.Range.Collapse(0)
>ENDWITH
>
>
>Thanks for your help.
>
>Ken

Word.Basic ??? Are you using word95 ? With word.basic the syntax of goto for a bookmark was (as shown in sample code) :

Goto(-1,,,"BookMarkName")

If it's word97 and later then use 'word.application'. Word.application still has word.basic as an object if you really need.
*!*	This example inserts first 10 recs from employee table
*!*	Bookmarks each as inserted
*!*	Moves odd recno() records to eof
*!*	Please notice that this is for word97
*!*	Word.basic commands work unchanged in word95 & word97 (Those used here)
*!*	Some sections are commented to show the same syntax (or alternative)
*!*	for VB and wordbasic

#Define NL Chr(13)
Public oWordDocument

*** 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
Wait Window Nowait "Creating Word Document..."

oWordDocument=Createobject("word.application")	&& Create word object
With oWordDocument.wordbasic
  .appshow							&& Show word app
  .filenewdefault        				&& New file, default template
  Scan While Recno() <= 10
    .formatfont(12,,6)					&& 12 points, red
    .editbookmark("b"+Alltrim(employee.emp_id),,1)   && Add bookmark using emp_id
    * oWordDocument.activedocument.bookmarks.add(cBookmark) - VB syntax
    *!*			lcBkmark = "b"+alltrim(employee.emp_id)
    *!*			lcBkmarkvalue = ltrim(str(recno()))+"-"+trim(employee.last_name)+","+employee.first_name
    *!*			? lcBkmark, lcBkmarkValue
    *!*			.setformresult(lcBkmark,lcBkmarkValue)
    .Insert(NL)
    * Insert employee name - recno is just for us to track
    .formatfont(10,,5)					&& 10 points, Magenta
    .Insert(employee.notes+NL+NL)  		&& Insert employee notes
    * Insert odd recs as selstart, even as selend into an array
    If Recno()%2 = 1
      Dimension aBookMarksRange[;
iif(type("aBookMarksRange")="U",1,;
alen(aBookMarksRange,1)+1),2]
    Endif
    Store "b"+Alltrim(employee.emp_id) To ;
      ("aBookMarksRange[alen(aBookMarksRange,1),"+Iif(Recno()%2=1,"1","2")+"]")
  Endscan
Endwith
If Type("aBookMarksRange")#"U"		&& Make sure bookmark array exist
  With oWordDocument.ActiveDocument  && Use VB syntax instead of wordbasic
    For ix=1 To Alen(aBookMarksRange,1)
      If .Bookmarks.Exists(aBookMarksRange[ix,1]) ;
          and .Bookmarks.Exists(aBookMarksRange[ix,2]) && Are they both defined ?

        .Range(.Bookmarks(aBookMarksRange[ix,1]).Range.Start, ;
          .Bookmarks(aBookMarksRange[ix,2]).Range.End).cut && Select & cut range
        *!*	.Range(.Bookmarks(aBookMarksRange[ix,1]).Range.Start, ;
        *!*	.Bookmarks(aBookMarksRange[ix,2]).Range.End).select && Select range
        *!*	oWordDocument.Selection.Cut		&& Cut selection
        oWordDocument.Selection.Goto(-1,,,"\EndOfDoc")	 && VB goto bookmark
        oWordDocument.Selection.Paste
        * Same word.basic way to cut and paste
        *!*	oWordDocument.wordbasic.editcut && Wordbasic cut method
        *!*	oWordDocument.wordbasic.endofdocument   && Wordbasic goto eod
        *!*	oWordDocument.wordbasic.editpaste && Wordbasic paste method
      Endif
*oWordDocument.wordbasic.setformresult(.Bookmarks(aBookMarksRange[ix,1]),;
   5+8+9,1)
    Endfor
  Endwith
  #Define msoShapeRectangle 1
  #Define msoShapeOval  9
  #Define msoCallOutTwo 2
  #Define msoCallOutThree 3
  With oWordDocument.ActiveDocument.Shapes
    .AddShape(msoShapeRectangle, 50, 100, 100, 200)
    With .AddCallout(msoCallOutTwo, 200, 170, 170, 40)
      .TextFrame.TextRange.Text = "My rectangle"
      With .Callout
        .Accent = .T.
        .Border = .F.
      Endwith
    Endwith
    With .AddCallout(msoCallOutThree, 320, 170, 170, 40)
      .TextFrame.TextRange.Text = "My callout 3"
      With .Callout
        .Accent = .T.
        .Border = .T.
      Endwith
    Endwith
  Endwith
Endif
Wait Clear
**** Set the LocaleId to the previous value
=Sys(3006,Val(nlLocaleId))
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform