Jump to content

Copying text from Word Document to paste into a Rich-Text webmail system


Go to solution Solved by Nine,

Recommended Posts

Posted

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?

Posted (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 by GMK
Forgot to proofread
Posted
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
Posted

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

 

Posted
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!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...