如何在Word.Application对象中移动光标 [英] How Can I Move The Cursor In Word.Application Object
问题描述
大家好,
我试图在自动程序的word文档中插入一些文本。
这是我的程序应该做的。
1.获取单词当前实例的对象(这没关系)
2.设置光标所在的范围(这是正常的)
3.插入一些文本 - 它有2行 - (这没关系)
4.格式化文本。 - 更改字体,大小,使其变为粗体 - (这没关系)
5.将光标移动到插入文本的末尾并按下回车键,这样我就可以开始输入新队。我需要更改Font.Bold = False(这不行)
是的,第五件事没有发生。这是我的代码
Hi all,
I am trying to insert some text in a word document from an autoit program.
This is my program is supposed to do.
1. Getting the object of word's current instance (This is OK)
2. Setting a range where the cursor locates (This is OK)
3. Insert some text - It has 2 lines - (This is OK)
4. Formatting thar text. - Change the font, size, make it bold - (This is OK)
5. Moving the cursor to the end of the inserted text and send an enter key press so that i can start typing from a new line. And i need to change the Font.Bold = False (This is NOT OK)
Yeah, the fifth thing is not happening. Here is my code
Local $wObj = ObjGet("","Word.Application") ; Here i got the word object
Local $doc = $wObj.ActiveDocument ; Here i set the current document
Local $range = _Word_DocRangeSet($doc,0) ; Here i set the range form current cursor location.
Local $Text = "This is First Line" & @CRLF & "This is Second Line" ; Text in 2 lines
$range.Text = $Text ; Here i insert the text into word
If Not @error Then ; If there is no error occurred, then
With $range.Font
.Bold = 1 ; I have changed the boldess
.Name = "Rachana" ; changed the font
.Size = 14 ; and the size
EndWith
Else
ConsoleWrite("Something went wrong buddy")
EndIf
$range.SetRange($range.ParagraphEnd, $range.Words.End + 1) ; Here is the problem. I want to move the range to the end of the current range.
Sleep(300) ; A short delay
wObj = 0 ; Terminating the object
Exit
所以,有人请帮我将范围移到当前范围的末尾。
So, somebody please help me to move the range to end of the current range.
推荐答案
wObj = ObjGet(,Word.Application);在这里,我得到了单词object
Local
wObj = ObjGet("","Word.Application") ; Here i got the word object Local
doc =
wObj.ActiveDocument;这里我设置当前文件
Local
wObj.ActiveDocument ; Here i set the current document Local
这篇关于如何在Word.Application对象中移动光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!