Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Kenneth Haugland 12-Jan-16 14:18pm    
In general, use Record macro and see what code you get from Word. Than it is gerally easy to figure out how to do it in VSTO
Vinod Kc 12-Jan-16 14:34pm    
@Kenneth Haugland, I don't know anything about macro. I just know to control word document with this scripting language.
Kenneth Haugland 12-Jan-16 14:36pm    
https://support.office.com/en-NZ/article/Record-or-run-a-macro-cd56fb86-d8b2-475c-ba39-9728389feeeb
Vinod Kc 12-Jan-16 14:42pm    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900