Helo, I have following problem. I want only to write some data read from DB in PB to a Word docment and then to print it out. I am using OLE - everything is OK - I am connected to MS Word, the file is opened, I can even print it ...., but I can't manage to write on a bookmark. I have already tried following, but nothing works: ole_word.object.Application.ActiveDocument.Bookmarks("testbook").Range.Text = "test value" Since I know that there can be troubles with bookmarks (defined x notdefined) in Word I thought that maybe it could be better to use the bookmarks check in VBA via my macro: macro: this works started directly from Word: Public Sub testmacro() If Application.ActiveDocument.Bookmarks.Exists("testbook") Then Application.ActiveDocument.Bookmarks("testbook").Range.Text = "test value" End If End Sub but then I am not able to call the Word function (macro) from PB script. None of following works: ole_word.Object.wordbasic.testmacro ole_word.Object.testmacro ole_word.Object.Call testmacro - this causes compilation error ??? Is it possible to call Word macros from PB or how to directly set the Bookmarks value ??? Thanks for any help Jiri
![]() |
0 |
![]() |
It's really interesting how the command is dependant on the version. We have Word 97 SR-2 and imagine what is working: ole_word.Object.Application.Documents.Open(ls_file) ole_word.Object.Application.Run(ls_macro) //!!!!!!! ole_word.Object.Application.ActiveDocument.PrintOut ole_word.Object.Application.ActiveDocument.Close() Jiri <Jiri.Felcman@noofs.abb.no> wrote in article <01bf73f5$2d738370$ca948589@nooft-w75108350>... > Helo, > > I have following problem. I want only to write some data read from DB in PB > to a Word docment and then to print it out. I am using OLE - everything is > OK - I am connected to MS Word, the file is opened, I can even print it > ..., but I can't manage to write on a bookmark. I have already tried > following, but nothing works: > > ole_word.object.Application.ActiveDocument.Bookmarks("testbook").Range.Text > = "test value" > > Since I know that there can be troubles with bookmarks (defined x > notdefined) in Word I thought that maybe it could be better to use the > bookmarks check in VBA via my macro: > > macro: this works started directly from Word: > Public Sub testmacro() > > If Application.ActiveDocument.Bookmarks.Exists("testbook") Then > Application.ActiveDocument.Bookmarks("testbook").Range.Text = "test > value" > End If > > End Sub > > but then I am not able to call the Word function (macro) from PB script. > None of following works: > > ole_word.Object.wordbasic.testmacro > ole_word.Object.testmacro > ole_word.Object.Call testmacro - this causes compilation error > > ??? Is it possible to call Word macros from PB or how to directly set the > Bookmarks value ??? > > Thanks for any help > > Jiri >
![]() |
0 |
![]() |
BUT - This doesn't work if you want to start macros (VBA procedures) with parameters. WHY ??? Jiri <Jiri.Felcman@noofs.abb.no> wrote in article <01bf73fd$888e23c0$ca948589@nooft-w75108350>... > It's really interesting how the command is dependant on the version. We > have Word 97 SR-2 and imagine what is working: > > ole_word.Object.Application.Documents.Open(ls_file) > ole_word.Object.Application.Run(ls_macro) //!!!!!!! > ole_word.Object.Application.ActiveDocument.PrintOut > ole_word.Object.Application.ActiveDocument.Close() > > Jiri <Jiri.Felcman@noofs.abb.no> wrote in article > <01bf73f5$2d738370$ca948589@nooft-w75108350>... > > Helo, > > > > I have following problem. I want only to write some data read from DB in > PB > > to a Word docment and then to print it out. I am using OLE - everything > is > > OK - I am connected to MS Word, the file is opened, I can even print it > > ..., but I can't manage to write on a bookmark. I have already tried > > following, but nothing works: > > > > > ole_word.object.Application.ActiveDocument.Bookmarks("testbook").Range.Text > > = "test value" > > > > Since I know that there can be troubles with bookmarks (defined x > > notdefined) in Word I thought that maybe it could be better to use the > > bookmarks check in VBA via my macro: > > > > macro: this works started directly from Word: > > Public Sub testmacro() > > > > If Application.ActiveDocument.Bookmarks.Exists("testbook") Then > > Application.ActiveDocument.Bookmarks("testbook").Range.Text = "test > > value" > > End If > > > > End Sub > > > > but then I am not able to call the Word function (macro) from PB script. > > None of following works: > > > > ole_word.Object.wordbasic.testmacro > > ole_word.Object.testmacro > > ole_word.Object.Call testmacro - this causes compilation error > > > > ??? Is it possible to call Word macros from PB or how to directly set the > > Bookmarks value ??? > > > > Thanks for any help > > > > Jiri > > >
![]() |
0 |
![]() |
Here is a small sample of commands that we use when communicating with MS Word. OLEObject iole_word STRING ls_doc STRING ls_bookmarkname STRING ls_bookmarkvalue // Set variables ls_doc = "mydoc.doc" // replace with db value if necessary ls_bookmarkname = "state_value" // replace with db value if necessary ls_bookmarkvalue = "California" // replace with db value if necessary // Instantiate oleobject iole_word = CREATE oleobject // Connect to Word iole_word.ConnectToNewObject("word.application.8") // Open Doc iole_word.Documents.Open(ls_doc) // Goto bookmark and insert bookmarkvalue (option #1) iole_word.ActiveDocument.Bookmarks.Item(ls_bookmarkname).Range.Text = ls_bookmarkvalue // Goto bookmark and insert bookmarkvalue (option #2) // Note: this is derived from word.basic (word95) when you had // to goto the bookmark and typetext your bookmarkvalue) iole_word.ActiveDocument.Bookmarks.Item(ls_bookmarkname).Select iole_word.Selection.TypeText(ls_bookmarkvalue) // Print Doc (w/ defaults) iole_word.ActiveDocument.PrintOut() // Close Doc (w/o saving) iole_word.Documents.Close(0) // Exit Word iole_word.Application.Quit(0) // Disconnect and destroy instance iole_word.DisconnectObject() Destroy iole_word ///////////////////////////////////////////////////////////////// // Additional Word Commands // Note: all of these can be found by // creating a macro in ms word and // converting to PB code. All of these // work for all versions of Word 97 I have // tested (sr0, sr1, & sr2). // // make word visible/invisible // iole_word.Visible = True // iole_word.Visible = False // // goto start of document // iole_word.Selection.HomeKey(6) // // goto end of document // iole_word.Selection.EndKey(6) // // goto beginning of current line // iole_word.Selection.HomeKey(5,x) // x = 0 [does not hold down shift key] // x = 1 [hold down shift key] // // goto end of current line // iole_word.Selection.EndKey(5,x) // x = 0 [does not hold down shift key] // x = 1 [hold down shift key] // // delete current selection // iole_word.Selection.Delete() // // enter new line // iole_word.Selection.TypeParagraph() // // move cursor right // iole_word.Selection.MoveRight(x,y,z) // x = 1 [move # of letters to right] // x = 2 [move # of words to right] // x = 3 [move # of sentences to right] // y = # [number to move right] // z = 0 [does not hold down shift key] // z = 1 [hold down shift key] // // move cursor left // iole_word.Selection.MoveLeft(x,y,z) // x = 1 [move # of letters to left] // x = 2 [move # of words to left] // x = 3 [move # of sentences to left] // y = # [number to move left] // z = 0 [does not hold down shift key] // z = 1 [hold down shift key] // ///////////////////////////////////////////////////////////////// // sample find/replace all (this will not // prompt the user once it starts) // ls_find = sle_find.Text // find text sle ls_repl = sle_replace.Text // replace text sle lb_matchcase = cbx_matchcase.Checked // match case checkbox // perform initial find iole_word.Selection.Find.MatchCase = lb_matchcase iole_word.Selection.Find.Text = ls_find lb_found = iole_word.Selection.Find.Execute() // replace text and look for next until no more are found DO WHILE lb_found ll_rc +=1 iole_word.Selection.TypeText(ls_repl) iole_word.Selection.Find.Text = ls_find sle_replaced.Text = STRING(ll_rc) // show user how many replaced lb_found = iole_word.Selection.Find.Execute() LOOP // // End of find/replace all ///////////////////////////////////////////////////////////////// Jiri <Jiri.Felcman@noofs.abb.no> wrote in message news:01bf73f5$2d738370$ca948589@nooft-w75108350... > Helo, > > I have following problem. I want only to write some data read from DB in PB > to a Word docment and then to print it out. I am using OLE - everything is > OK - I am connected to MS Word, the file is opened, I can even print it > ..., but I can't manage to write on a bookmark. I have already tried > following, but nothing works: > > ole_word.object.Application.ActiveDocument.Bookmarks("testbook").Range.Text > = "test value" > > Since I know that there can be troubles with bookmarks (defined x > notdefined) in Word I thought that maybe it could be better to use the > bookmarks check in VBA via my macro: > > macro: this works started directly from Word: > Public Sub testmacro() > > If Application.ActiveDocument.Bookmarks.Exists("testbook") Then > Application.ActiveDocument.Bookmarks("testbook").Range.Text = "test > value" > End If > > End Sub > > but then I am not able to call the Word function (macro) from PB script. > None of following works: > > ole_word.Object.wordbasic.testmacro > ole_word.Object.testmacro > ole_word.Object.Call testmacro - this causes compilation error > > ??? Is it possible to call Word macros from PB or how to directly set the > Bookmarks value ??? > > Thanks for any help > > Jiri
![]() |
0 |
![]() |
The iole_word.Selection.TypeText command works, but what if I want to bring in a bmp file. would it be iole_word.Selection.TypePicture? Tom Bratina wrote in message ... >Here is a small sample of commands that we use when communicating with MS >Word. > > > >OLEObject iole_word >STRING ls_doc >STRING ls_bookmarkname >STRING ls_bookmarkvalue > >// Set variables >ls_doc = "mydoc.doc" // replace with db value if necessary >ls_bookmarkname = "state_value" // replace with db value if necessary >ls_bookmarkvalue = "California" // replace with db value if necessary > >// Instantiate oleobject >iole_word = CREATE oleobject > >// Connect to Word >iole_word.ConnectToNewObject("word.application.8") > >// Open Doc >iole_word.Documents.Open(ls_doc) > >// Goto bookmark and insert bookmarkvalue (option #1) >iole_word.ActiveDocument.Bookmarks.Item(ls_bookmarkname).Range.Text = >ls_bookmarkvalue > >// Goto bookmark and insert bookmarkvalue (option #2) >// Note: this is derived from word.basic (word95) when you had >// to goto the bookmark and typetext your bookmarkvalue) >iole_word.ActiveDocument.Bookmarks.Item(ls_bookmarkname).Select >iole_word.Selection.TypeText(ls_bookmarkvalue) > >// Print Doc (w/ defaults) >iole_word.ActiveDocument.PrintOut() > >// Close Doc (w/o saving) >iole_word.Documents.Close(0) > >// Exit Word >iole_word.Application.Quit(0) > >// Disconnect and destroy instance >iole_word.DisconnectObject() >Destroy iole_word > >///////////////////////////////////////////////////////////////// >// Additional Word Commands >// Note: all of these can be found by >// creating a macro in ms word and >// converting to PB code. All of these >// work for all versions of Word 97 I have >// tested (sr0, sr1, & sr2). >// >// make word visible/invisible >// iole_word.Visible = True >// iole_word.Visible = False >// >// goto start of document >// iole_word.Selection.HomeKey(6) >// >// goto end of document >// iole_word.Selection.EndKey(6) >// >// goto beginning of current line >// iole_word.Selection.HomeKey(5,x) >// x = 0 [does not hold down shift key] >// x = 1 [hold down shift key] >// >// goto end of current line >// iole_word.Selection.EndKey(5,x) >// x = 0 [does not hold down shift key] >// x = 1 [hold down shift key] >// >// delete current selection >// iole_word.Selection.Delete() >// >// enter new line >// iole_word.Selection.TypeParagraph() >// >// move cursor right >// iole_word.Selection.MoveRight(x,y,z) >// x = 1 [move # of letters to right] >// x = 2 [move # of words to right] >// x = 3 [move # of sentences to right] >// y = # [number to move right] >// z = 0 [does not hold down shift key] >// z = 1 [hold down shift key] >// >// move cursor left >// iole_word.Selection.MoveLeft(x,y,z) >// x = 1 [move # of letters to left] >// x = 2 [move # of words to left] >// x = 3 [move # of sentences to left] >// y = # [number to move left] >// z = 0 [does not hold down shift key] >// z = 1 [hold down shift key] >// >///////////////////////////////////////////////////////////////// >// sample find/replace all (this will not >// prompt the user once it starts) >// > >ls_find = sle_find.Text // find text sle >ls_repl = sle_replace.Text // replace text sle >lb_matchcase = cbx_matchcase.Checked // match case checkbox > >// perform initial find >iole_word.Selection.Find.MatchCase = lb_matchcase >iole_word.Selection.Find.Text = ls_find >lb_found = iole_word.Selection.Find.Execute() > >// replace text and look for next until no more are found >DO WHILE lb_found > ll_rc +=1 > iole_word.Selection.TypeText(ls_repl) > iole_word.Selection.Find.Text = ls_find > sle_replaced.Text = STRING(ll_rc) // show user how many replaced > lb_found = iole_word.Selection.Find.Execute() >LOOP > >// >// End of find/replace all >///////////////////////////////////////////////////////////////// > > > > >Jiri <Jiri.Felcman@noofs.abb.no> wrote in message >news:01bf73f5$2d738370$ca948589@nooft-w75108350... >> Helo, >> >> I have following problem. I want only to write some data read from DB in >PB >> to a Word docment and then to print it out. I am using OLE - everything is >> OK - I am connected to MS Word, the file is opened, I can even print it >> ..., but I can't manage to write on a bookmark. I have already tried >> following, but nothing works: >> >> >ole_word.object.Application.ActiveDocument.Bookmarks("testbook").Range.Text >> = "test value" >> >> Since I know that there can be troubles with bookmarks (defined x >> notdefined) in Word I thought that maybe it could be better to use the >> bookmarks check in VBA via my macro: >> >> macro: this works started directly from Word: >> Public Sub testmacro() >> >> If Application.ActiveDocument.Bookmarks.Exists("testbook") Then >> Application.ActiveDocument.Bookmarks("testbook").Range.Text = "test >> value" >> End If >> >> End Sub >> >> but then I am not able to call the Word function (macro) from PB script. >> None of following works: >> >> ole_word.Object.wordbasic.testmacro >> ole_word.Object.testmacro >> ole_word.Object.Call testmacro - this causes compilation error >> >> ??? Is it possible to call Word macros from PB or how to directly set the >> Bookmarks value ??? >> >> Thanks for any help >> >> Jiri > >
![]() |
0 |
![]() |