hogfan Posted September 25, 2015 Share Posted September 25, 2015 (edited) Hello, I am trying to work out an issue where i am using Word.au3 and the _Word_DocFindReplace function to find and replace existing fields in a a Word document with user input. All fields in the word document are getting replaced correctly with the exception of a list of cities. The string that I am trying drop into the Word document is formatted like this New YorkLos AngelesNashvilleSeattle This issue is that when this is pasted into the Word Document with the _Word_DocFindReplace function, it goes in with a leading space on the first entry, and each additional line has the "square" characters in front of the city names. This is obviously some sort of Word text formatting issue. How can I make this paste in as "Plain Text" with the hard return after each city name, but without the unwanted characters? I will never understand Microsoft's reasoning for making the default paste action to "keep formatting of the text you are pasting", Any help is appreciated on this one. -hogfan Edited September 29, 2015 by hogfan Link to comment Share on other sites More sharing options...
hogfan Posted September 25, 2015 Author Share Posted September 25, 2015 It is definitely and issue with the hard returns being pasted. I tried a workaround in the Word document by creating a 1 x 1 table with no border and putting my field to be replaced in there. When the paste goes in now it's a single line that looks like this:New York[][]LOS Angeles[][]Nashville[][]Seattle Link to comment Share on other sites More sharing options...
water Posted September 25, 2015 Share Posted September 25, 2015 Can you please post your script so we can see how the user data is pasted into the Word document? 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...
hogfan Posted September 25, 2015 Author Share Posted September 25, 2015 (edited) I can't post the entire script as it contains some company sensitive data, but the function looks similar to this example I put together. I have even tried here to use stringsplit function to split the entered contents of the Edit control by the the @CRLF, & and the rebuild a clean string, but this stil does not seem to be working. Func _Generate () ;Read the user input from the form $myCities = GUICtrlRead($edtCities) ;Trim off any leading or trailing spaces $myCities = _AllTrim($myCities) ;Deal with MS Word Multi-line return/paste BS Local $arrCities = StringSplit($myCities,@CRLF, $STR_ENTIRESPLIT) ;Verify the array is getting populated by displaying it _ArrayDisplay($arrCities) ;build the new string value from the array elements to clean up any characters Word doesn't like ;set initial value for variable $myFormattedCities = Null ;Loop through the array and build out the new string For $i = 0 To UBound($arrCities) -1 $myFormattedCities = $myFormattedCities & $arrCities[$i] & @CRLF Next ;display a message box to preview the string Msgbox(0, "Test", $myFormattedCities) $selectedTemplate = GUICtrlRead($cmbTemplate) $FullTemplatePath = @ScriptDir & "\templates\" & $selectedTemplate ;Create the document from the Word template Local $oWord = _Word_Create(False, True) ;Msgbox(0,"", "Created Word Instance") Local $oDoc = _Word_DocOpen($oWord, $FullTemplatePath) ;Msgbox(0,"", "Successfully Opened Fulfillment Letter Template") Local $oFind = _Word_DocFindReplace($oDoc, "[CITIES]", $myFormattedCities) $mySavePath = $SavePath & "\" & "test.doc" Local $returnSave = _Word_DocSaveAs($oDoc, $mySavePath) ;If there is a problem saving the file to the desktop display an error message If $returnSave = 0 Then MsgBox(48, "Error Saving File", "The file was unable to save! Please ensure you have write permission to the specified save directory!") _Word_Quit($oWord) Return EndIf EndFunc Edited September 25, 2015 by hogfan Link to comment Share on other sites More sharing options...
water Posted September 25, 2015 Share Posted September 25, 2015 You could try this to clean the string:$myCities = $oWord.CleanString($myCities)Unfortunately a bullet is translated to a space character (CleanString) so you might need to translate@CRLF & " " to @CRLF or@CR & " " to @CR or@LF & " " to @LF 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...
hogfan Posted September 25, 2015 Author Share Posted September 25, 2015 Strange. When I use: $myCities = $oWord.CleanString($myCities)I display the string in a messagebox before and after the cleanstring function, and afte the function is run the string is empty (or all spaces, not sure which) Link to comment Share on other sites More sharing options...
water Posted September 25, 2015 Share Posted September 25, 2015 How do you create the list of cities? I assume by an AutoIt RichEdit Control. 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...
hogfan Posted September 25, 2015 Author Share Posted September 25, 2015 Correct. The user enters the list into a Multi-line AutoIT RichEdit Control. Link to comment Share on other sites More sharing options...
water Posted September 25, 2015 Share Posted September 25, 2015 Can't you just grab the hex value of the bullets and use StringReplace to remove them? 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...
hogfan Posted September 28, 2015 Author Share Posted September 28, 2015 Well, there are no bullets until the contents of the edit control get put into Word. I am already doing a Find/Replace function to to replace a non- bulleted value that already exists in my Word template. Link to comment Share on other sites More sharing options...
hogfan Posted September 28, 2015 Author Share Posted September 28, 2015 I was going to replace the unicode character with a backspace, but Word won't show me the Unicode value for the character, even after changing to a Unicode font. Super frustrating. I'm using Word 2013. I tried hitting ALT+X, and that doesn't work........I found another article showing to highlight the character and click the show unicode button on the toolbar, but apparently that doesn't exist in Word 2013. Link to comment Share on other sites More sharing options...
water Posted September 29, 2015 Share Posted September 29, 2015 As you get the text from your GUI use AutoIt to display the text in hex. 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...
hogfan Posted September 29, 2015 Author Share Posted September 29, 2015 Finally got it sorted out. The solution was to use the "@CR" instead of "@CRLF" when building the string. Thanks you for the assistance. I think I am good to go now Link to comment Share on other sites More sharing options...
water Posted September 29, 2015 Share Posted September 29, 2015 Glad you got it sorted out 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...
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