saywell Posted August 5, 2010 Share Posted August 5, 2010 (edited) I'm replacing various bits of text with strings from my script.All work except for 2 cases in a text box (address header needed to keep right justified stuff in header as well as left-justified main text].According to the help, _WordDocFindReplace range defaults to searching the whole document:$v_SearchRange | 0 = (Default) Specifies the entire documentAny range object[edit] It works with tables, so I'll try using them rather than text box!But this isn't working for me. Am I doing something wrong, or is this a limitation of the UDF? Is there another way to do this? My VBA skills are rudimentary - as in my other recent query - so not keen on tackling multi-line VBAs!thanks,William Edited August 5, 2010 by saywell Link to comment Share on other sites More sharing options...
water Posted August 5, 2010 Share Posted August 5, 2010 (edited) Textboxes are hidden in the fields collection.One solution is to run the search two times: Once for the text and a second time for the fields.Maybe this link helps. Edited August 5, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
saywell Posted August 5, 2010 Author Share Posted August 5, 2010 Textboxes are hidden in the fields collection.One solution is to run the search two times: Once for the text and a second time for the fields.Maybe this link helps.Thanks, water.That's a bit beyond my present knowledge, but I'll have a good read of your links.For now, I've put the text box contents in a table, instead (it was just a document header, needing the S&R to add the correct extension and email address according to its creator).Regards,William Link to comment Share on other sites More sharing options...
saywell Posted August 6, 2010 Author Share Posted August 6, 2010 Sorry to be back here so soon, but I've discovered some odd behaviour in the _WordDocFindReplace function in my script. I'm replacing CCCC in my new document with $ClinicCode, where the clinic code is in the format [3letters]/[3digits]. If I use 999 as the 3 digits - eg ABC/999 the search and replace puts 069 in the document! It does this even if I replace the string in the command with "ABC/999" so it's not a string error. And it works fine for other numbers with 3 repeated digits. However, if I use n99 it puts in n06 [where n is another digit]. Though nn9 renders correctly. If I do a manual S&R in word, it works as expected, so it's not an odd word setting. Is there a special useage of '99' in the word udf? Any thoughts, anyone? regards, William Link to comment Share on other sites More sharing options...
water Posted August 6, 2010 Share Posted August 6, 2010 Just tried it with Word 2002 and it works fine for me. #include <word.au3> $oWord = _WordCreate("C:\temp\test.doc") $oDoc = _WordDocGetCollection($oWord, 0) _WordDocFindReplace($oDoc,"CCCC","ABC/999") My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
saywell Posted August 6, 2010 Author Share Posted August 6, 2010 Just tried it with Word 2002 and it works fine for me. #include <word.au3> $oWord = _WordCreate("C:\temp\test.doc") $oDoc = _WordDocGetCollection($oWord, 0) _WordDocFindReplace($oDoc,"CCCC","ABC/999") Mine's 2002 too. And testing with a code snippet like yours works! So, back to the code, and I see that my template has a '99' to be replaced by @MDAY - and today's the 6th, so @MDY = 06!! How stupid can I get? I've changed the 99 to XX so it's not changing the 99 that might appear in clinic code. Regards, William Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now