obscurant1st Posted April 30, 2010 Posted April 30, 2010 Ii have wordfl, in that how can i find one particular set of continuous words and replace the word coming after that. for example: in my word doc, there are instances like "the filename is" appearing many times. I have to replace the word coming after this sentance ie "the filename is" So the file contains "the filename is" aaa "the filename is" bbb "the filename is" kjhdfjdhf I want to replace everything with a word aa.doc, so the result will be "the filename is" aa.doc "the filename is" aa.doc "the filename is" aa.doc can i do this by any means?? [u]We don't need people who can spit back facts. We've got Google."[/u] WebguruBB - Free Hosting, Domains, and SEO articles.Awesome Techs - Tips, Tricks and Some Technology NewsCool Facts - Cool Facts, Fun Facts, Weird Facts etc.
Moderators Melba23 Posted April 30, 2010 Moderators Posted April 30, 2010 obscurant1st,This SRE seems to work: $sText = "the filename is aaa and more text the filename is bbb and more text" & @CRLF & "the filename is kjhdfjdhf and more text" $sCorrected = StringRegExpReplace($sText, "(?i)(?U)(the filename is (\b.+\b))", "the filename is aa.doc") ConsoleWrite($sCorrected & @CRLF)No doubt a real SRE guru will be along shortly with a much more snazzy version if you want to hang around. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
obscurant1st Posted April 30, 2010 Author Posted April 30, 2010 obscurant1st, This SRE seems to work: $sText = "the filename is aaa and more text the filename is bbb and more text" & @CRLF & "the filename is kjhdfjdhf and more text" $sCorrected = StringRegExpReplace($sText, "(?i)(?U)(the filename is (\b.+\b))", "the filename is aa.doc") ConsoleWrite($sCorrected & @CRLF) No doubt a real SRE guru will be along shortly with a much more snazzy version if you want to hang around. M23 But here in my case $sText is in a word document. So how can i get the contents to $sText? [u]We don't need people who can spit back facts. We've got Google."[/u] WebguruBB - Free Hosting, Domains, and SEO articles.Awesome Techs - Tips, Tricks and Some Technology NewsCool Facts - Cool Facts, Fun Facts, Weird Facts etc.
Moderators Melba23 Posted April 30, 2010 Moderators Posted April 30, 2010 obscurant1st,Ever heard of "Save As..."? Save the Word file as a .txt file and then read it into your script with FileRead. Once you have finished changing it, write teh result back to the file with FileWrite and then import into Word. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
obscurant1st Posted May 2, 2010 Author Posted May 2, 2010 obscurant1st,Ever heard of "Save As..."? Save the Word file as a .txt file and then read it into your script with FileRead. Once you have finished changing it, write teh result back to the file with FileWrite and then import into Word. M23But saving it as txt file will cause the formatting of my word file to loose right?if not its ok. [u]We don't need people who can spit back facts. We've got Google."[/u] WebguruBB - Free Hosting, Domains, and SEO articles.Awesome Techs - Tips, Tricks and Some Technology NewsCool Facts - Cool Facts, Fun Facts, Weird Facts etc.
Moderators Melba23 Posted May 2, 2010 Moderators Posted May 2, 2010 obscurant1st,saving it as txt file will cause the formatting of my word file to looseCorrect.I can only suggest you do which ever the following you think would take the shortest time: - 1. Use Word's built-in VB scripting to change the text. I imagine there are forums for that which can help you.- 2. Go manually through the file and change the text.- 3. Do as I suggested and reformat the file afterwards.M23P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
obscurant1st Posted May 4, 2010 Author Posted May 4, 2010 I think 1st option will do the work for me. Can you suggest any forums which can help me? [u]We don't need people who can spit back facts. We've got Google."[/u] WebguruBB - Free Hosting, Domains, and SEO articles.Awesome Techs - Tips, Tricks and Some Technology NewsCool Facts - Cool Facts, Fun Facts, Weird Facts etc.
Moderators Melba23 Posted May 4, 2010 Moderators Posted May 4, 2010 Let me Google that for you. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Makaule Posted May 9, 2010 Posted May 9, 2010 I dont know is it solved or not, but you could use that example: http://www.autoitscript.com/forum/index.php?showtopic=114123&st=0&p=798037&hl=Word&fromsearch=1&#entry798037
obscurant1st Posted May 12, 2010 Author Posted May 12, 2010 its not solved, i am still trying. [u]We don't need people who can spit back facts. We've got Google."[/u] WebguruBB - Free Hosting, Domains, and SEO articles.Awesome Techs - Tips, Tricks and Some Technology NewsCool Facts - Cool Facts, Fun Facts, Weird Facts etc.
saywell Posted August 13, 2010 Posted August 13, 2010 (edited) its not solved, i am still trying. How about: $oWordApp = _WordCreate ($Filename, 0, 0) ; Display the text within the document $sContent = $oWordApp.Activedocument.Range.Text MsgBox(0, "Document Text", $sContent) _WordQuit ($oWordApp) William Edited August 13, 2010 by saywell
MeMeMe Posted August 13, 2010 Posted August 13, 2010 Two good, related word groups are: http://groups.yahoo.com/group/Word_VBA http://groups.yahoo.com/group/Word_DocDesign You'll be able to find out how to do what you need natively within word. You may not need a macro, this might work: Open the Find & replace dialog (CTRL+H) Make sure the Use Wildcards, or use Pattern Matching box is ticked. In the Find: box, enter the filename is <*> In the replace box, enter the filename is aa.doc "<" is the wildcard for start of a word, ">" is the end of a word, and "*" is any characters between those two - so that should select "the filename is " and whatever single word follows. It then replaces it with "the filename is aa.doc" Make a backup of your document first, and check the output thoroughly!
Malkey Posted August 13, 2010 Posted August 13, 2010 Try the example under the _WordDocFindReplace function in the AutoIt help file.
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