Ok, I’ll admit it i’m lost. What works in VBA doesn’t work at all in Navision. Maybe someone can explain to me why the “expand” method below doesn’t work. (XP OS + Office XP) [code] variables: AWordApp Automation ‘Microsoft Word 10.0 Object Library’.Application ARngFind Automation ‘Microsoft Word 10.0 Object Library’.Range vConstFindStop ‘Variant vConstParagraph ‘Variant NO ‘Variant YES ‘Variant tFindValue ‘Text code: // constants NO := FALSE; YES := TRUE; vConstFindStop := 0; vConstParagraph := 10; // find CLEAR(ARngFind); ARngFind := AWordApp.ActiveDocument.Content; tFindValue := STRSUBSTNO(’%1’, ‘text1’); ARngFind.Find.Execute(tFindValue, NO, NO, NO, NO, NO, YES, vConstFindStop, NO); // search for the text “text1” and finds it!! tResult := STRSUBSTNO(‘Start = %1 End = %2’, ARngFind.Start, ARngFind.“End”); IF CONFIRM(’%1’, FALSE, tResult) THEN EXIT; //Shows: Start = 188 End = 192 ARngFind.Expand(vConstParagraph); // <----- expand doesn’t work tResult := STRSUBSTNO(‘Start = %1 End = %2’, ARngFind.Start, ARngFind.“End”); IF CONFIRM(’%1’, FALSE, tResult) THEN EXIT; //Shows: Start = 188 End = 192 Text in word document: bla bla bla bla … These words around “text1” are not selected with the expand method … bla bla bla bla
Hi, I’ve tried the following code and it works (Office 2000). I think the only problem is the value of the Paragraph constant (according to VBA help, paragraph is 4, not 10 - this is Row) The document has the following text: bla bla bla … This is a Navision test … bla bla bla Variables: wdApp Automation 'Microsoft Word 9.0 Object Library'.Application wdRange Automation 'Microsoft Word 9.0 Object Library'.Range FileName Text 250 FindText Text 250 Yes Boolean No Boolean StopConstant Integer ParagraphConstant Integer Code: FileName := 'C:\Bla bla bla.doc'; FindText := 'Navision'; Yes := TRUE; No := FALSE; StopConstant := 0; ParagraphConstant := 4; CREATE(wdApp); wdApp.Documents.Open(FileName); wdRange := wdApp.ActiveDocument.Content; wdRange.Find.Execute(FindText,No,No,No,No,No,Yes,StopConstant,No); MESSAGE('Start %1\End %2\Text %3',wdRange.Start,wdRange."End",wdRange.Text); wdRange.Expand(ParagraphConstant); MESSAGE('Start %1\End %2\Text %3',wdRange.Start,wdRange."End",wdRange.Text);
The 1st message is: Start 51 End 58 Text Navision But the 2nd message is: Start 41 End 63 Text This is a Navision test I hope this proves helpful
Great, i was about to give up, will try out later and let you know the result!
Yes, it works, i typed/copied the wrong value in the constant, aarrggh. Now on to the next problem.