ThomasBennett Posted February 7 Posted February 7 Good morning, everyone, Thank you in advance for your time and consideration. I am trying to use _Word_DocRangeSet to set the range and have everything between "!@" and "#$" selected; this is the entire word document. I have !@ at the beginning of the Word document. I have #$ at the end of the Word document. I am not doing something correctly to have the .selection highlight what needs to be highlighted to copy the text. #include "wd_core.au3" #include "wd_helper.au3" #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Date.au3> #include <Array.au3> #include <File.au3> #include <Excel.au3> #include <Word.au3> Local $sDesiredCapabilities, $sFileOpenDialog, $sRange, $aResult, $sEmailMessage, $sFile, $iTerminate, $sDocName1, $oWord, $oDoc Local $oRange_Start, $oRange_End, $webmail_message_file, $oRangeActual, $sClipboard HotKeySet ("{ESC}", "Terminate") $oWord = _Word_Create() $webmail_message_file = @ScriptDir & "\Email_Message_Template.docx" $oDoc = _Word_DocOpen($oWord, $webmail_message_file) $oRange_Start = _Word_DocFind($oDoc, "!@") $oRange_End = _Word_DocFind($oDoc, "#$") $oRange_Actual = _Word_DocRangeSet($oDoc, -1, $oRange_Start, Default, $oRange_End, Default) $oRange_Actual.Selection ;MsgBox(0, "$oRange_Actual", $oRange_Actual) Exit What am I missing?
GMK Posted February 7 Posted February 7 (edited) _Word_DocRangeSet only sets the range. It doesn't select it. $oRange_Actual = _Word_DocRangeSet($oDoc, -1, $oRange_Start, Default, $oRange_End, Default) $oRange_Actual.Select MsgBox(0, "$oRange_Actual", $oRange_Actual.Selection) Edited February 7 by GMK Forgot to proofread
ThomasBennett Posted February 7 Author Posted February 7 13 minutes ago, GMK said: _Word_DocRangeSet only sets the range. It doesn't select it. $oRange_Actual = _Word_DocRangeSet($oDoc, -1, $oRange_Start, Default, $oRange_End, Default) $oRange_Actual.Select MsgBox(0, "$oRange_Actual", $oRange_Actual.Selection) Thank you @GMK. Should I see it actually highlight the selection? In some of my testing I saw it highlight so I wanted to double-check because it isn't highlighting when $oRange_Actual.Select is used. Also, I am running Microsoft Word Version 2408 (Build 17928.20392 (Microsoft 365)) on Windows 11 if there are different VBA calls that should be made.
Solution Nine Posted February 7 Solution Posted February 7 Try this : #include <Word.au3> Local $oWord = _Word_Create() Local $webmail_message_file = @ScriptDir & "\Test.docx" Local $oDoc = _Word_DocOpen($oWord, $webmail_message_file) ; to select the whole document $oDoc.Select Sleep(2000) ; to select whole document between "!@" and "#$" Local $oRange = $oDoc.range(2, $oDoc.Characters.Count - 3) $oRange.Select ThomasBennett 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
ThomasBennett Posted February 7 Author Posted February 7 13 minutes ago, Nine said: Try this : #include <Word.au3> Local $oWord = _Word_Create() Local $webmail_message_file = @ScriptDir & "\Test.docx" Local $oDoc = _Word_DocOpen($oWord, $webmail_message_file) ; to select the whole document $oDoc.Select Sleep(2000) ; to select whole document between "!@" and "#$" Local $oRange = $oDoc.range(2, $oDoc.Characters.Count - 3) $oRange.Select Well I was over doing it by a lot... thank you @Nine! This is exactly what I was looking for ; to select the whole document $oDoc.Select Now to figure out how to copy the selection into the clipboard. I'm going to do a deeper dive in the Microsoft Word VBA commands there's probably something there that will do this too. Thank you!
GMK Posted February 7 Posted February 7 I was wondering why you didn't just select the document but I wasn't going to question it. You can find more VBA info here, if I'm not mistaken. ThomasBennett 1
Nine Posted February 7 Posted February 7 32 minutes ago, ThomasBennett said: Now to figure out how to copy the selection into the clipboard Just put that after the select : $oWord.Selection.Copy ThomasBennett 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
ThomasBennett Posted February 7 Author Posted February 7 6 minutes ago, Nine said: $oWord.Selection.Copy @Nine, again thank you! I kept getting an object error and didn't realize that I needed to use $oWord instead of $oDoc!
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