Jump to content

controlsettext


Recommended Posts

Is there a question here?

Scary I know but one of you will be the lucky guy to be awarded the 5 * scripter of the month award. So who is it going to be then?

Who will be first, who is the best? Who is the mac daddy of AutoIT?

Ready, set..... GO FOR YOUR KEYBOARDS!

Link to comment
Share on other sites

Scary I know but one of you will be the lucky guy to be awarded the 5 * scripter of the month award. So who is it going to be then?

Who will be first, who is the best? Who is the mac daddy of AutoIT?

Ready, set..... GO FOR YOUR KEYBOARDS!

LOL

Ok well to put it simply

i need to change the text of a document without using SEND commands

any ideas?

(its word 2003)

Link to comment
Share on other sites

:whistle:

You need to ask a question (preferably with as much detail as possible) before we can help you.

I have a word document that contains dummy pieces of text

like this

[name]

[address1]

[address2]

Dear [name]

I have a script that contains variables like

$name = "nick christou"

$address1="6 south island place"

$address2="London"

I want to modify the word document to replace these dummy pieces of text with my strings

kind of like

ControlSetText ( "mydoc.doc - Microsoft Word", "[name]", "", $name , -1 )

except this doesnt work, i think because word returns no control IDs hence i have left it blank and also tried edit1 and -1

Link to comment
Share on other sites

  • Moderators

When you say "dummy pieces", are you refering to fields? If so then you will need to use com objects to update the fields with your variables. Otherwise if they are just text, then you can still use com but with a find method.

Edit: spelling

Edited by big_daddy
Link to comment
Share on other sites

When you say "dummy pieces", are you refering to fields? If so then you will need to use com objects to update the fields with your variables. Otherwise if they are just text, then you can still use com but with a find method.

Edit: spelling

i cant use COM cos smoke doesnt know how to do that

Link to comment
Share on other sites

  • Moderators

Ha!!, how the hell did I get brought into this :whistle:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

There are lots of contacts with SmOke you aren't aware of.

Ask his wife

:whistle:

im off

and dissapointed cos i've seen some impressive stuff here but nobody seems to be able to just change some text in a word doc

im amazed

i think there will be a workaround, open the file in raw mode and replace things (ouch) use another prog to do the replace, @SW_HIDE word and use SEND keys

dunno

will let you know anyhow what worked

Link to comment
Share on other sites

  • Moderators

So do you want help on this or not? If you do, then you need to answer my question above.

Edit: Just read your previous post. Do you seriously expect an answer to your "question" with what you have provided so far?

Edited by big_daddy
Link to comment
Share on other sites

So do you want help on this or not? If you do, then you need to answer my question above.

Edit: Just read your previous post. Do you seriously expect an answer to your "question" with what you have provided so far?

What do you need to know?

Open word

type in [blank]

save it

now change that [blank] piece of text u just typed automatically

i really dont understand what else i need to tell you

i want to do an automatic find and replace on a word doc

im shocked nobody has done this before

Link to comment
Share on other sites

So do you want help on this or not? If you do, then you need to answer my question above.

Edit: Just read your previous post. Do you seriously expect an answer to your "question" with what you have provided so far?

What do you need to know?

Open word

type in [blank]

save it

now change that [blank] piece of text u just typed automatically

i really dont understand what else i need to tell you

i want to do an automatic find and replace on a word doc

im shocked nobody has done this before

Link to comment
Share on other sites

  • Moderators

This does what you are wanting.

Requires:

Word.au3 - check my signature

#include <Word.au3>

; Register the default Word.au3 COM Error Handler
_WordErrorHandlerRegister ()

; Specify a file path for later use
$sFilePath = @ScriptDir & "\Test.doc"

; Try to attach to existing word window with the specified
; file, if one does not exist it will be created
$oWordApp = _WordCreate ($sFilePath)
Sleep(2000)
; Get reference to the active document
$oDoc = $oWordApp.ActiveDocument
; Get a range of the entire document
$oRng = $oDoc.Range
; Set the text for the entire document
$oRng.Text = "[name]" & @CRLF & @CRLF & _
        "[address1]" & @CRLF & @CRLF & _
        "[address2]" & @CRLF & @CRLF & _
        "Dear [name]"

Sleep(2000)
; Close document, saving changes, with original document format
_WordDocumentClose($oDoc, -1, 1)

Sleep(2000)
; Open the document, returning the active document object
$oDoc = _WordDocumentOpen($oWordApp, $sFilePath)
Sleep(1000)
; Find and replace text within the document
_FindReplace($oDoc, "[name]", "Joe Shmoe")
Sleep(1000)
; Find and replace text within the document
_FindReplace($oDoc, "[address1]", "12345 Broadway Ave.")
Sleep(1000)
; Find and replace text within the document
_FindReplace($oDoc, "[address2]", "Los Angeles, CA 54321")

Func _FindReplace($o_object, $s_search, $s_replace)
    If Not IsObj($o_object) Then
        SetError(1)
        Return 0
    EndIf
    
    $o_Rng = $o_object.Range
    $o_Find = $o_Rng.Find
    
    $o_Find.Execute ( _
            $s_search, _ ; FindText
            False, _ ; MatchCase
            True, _ ; MatchWholeWord
            False, _ ; MatchWildcards
            False, _ ; MatchSoundsLike
            False, _ ; MatchAllWordForms
            True, _ ; Forward
            1, _ ; wdFindStop = 0, wdFindContinue = 1, wdFindAsk = 2
            False, _ ; Format
            $s_replace, _ ; ReplaceWith
            2)  ; wdReplaceNone = 0, wdReplaceOne = 1, wdReplaceAll = 2
EndFunc   ;==>_FindReplace
Link to comment
Share on other sites

BD i will give this a go sorry i didnt reply earlier it was 1am had to sleeeep!

This does what you are wanting.

Requires:

Word.au3 - check my signature

#include <Word.au3>

; Register the default Word.au3 COM Error Handler
_WordErrorHandlerRegister ()

; Specify a file path for later use
$sFilePath = @ScriptDir & "\Test.doc"

; Try to attach to existing word window with the specified
; file, if one does not exist it will be created
$oWordApp = _WordCreate ($sFilePath)
Sleep(2000)
; Get reference to the active document
$oDoc = $oWordApp.ActiveDocument
; Get a range of the entire document
$oRng = $oDoc.Range
; Set the text for the entire document
$oRng.Text = "[name]" & @CRLF & @CRLF & _
        "[address1]" & @CRLF & @CRLF & _
        "[address2]" & @CRLF & @CRLF & _
        "Dear [name]"

Sleep(2000)
; Close document, saving changes, with original document format
_WordDocumentClose($oDoc, -1, 1)

Sleep(2000)
; Open the document, returning the active document object
$oDoc = _WordDocumentOpen($oWordApp, $sFilePath)
Sleep(1000)
; Find and replace text within the document
_FindReplace($oDoc, "[name]", "Joe Shmoe")
Sleep(1000)
; Find and replace text within the document
_FindReplace($oDoc, "[address1]", "12345 Broadway Ave.")
Sleep(1000)
; Find and replace text within the document
_FindReplace($oDoc, "[address2]", "Los Angeles, CA 54321")

Func _FindReplace($o_object, $s_search, $s_replace)
    If Not IsObj($o_object) Then
        SetError(1)
        Return 0
    EndIf
    
    $o_Rng = $o_object.Range
    $o_Find = $o_Rng.Find
    
    $o_Find.Execute ( _
            $s_search, _ ; FindText
            False, _ ; MatchCase
            True, _ ; MatchWholeWord
            False, _ ; MatchWildcards
            False, _ ; MatchSoundsLike
            False, _ ; MatchAllWordForms
            True, _ ; Forward
            1, _ ; wdFindStop = 0, wdFindContinue = 1, wdFindAsk = 2
            False, _ ; Format
            $s_replace, _ ; ReplaceWith
            2)  ; wdReplaceNone = 0, wdReplaceOne = 1, wdReplaceAll = 2
EndFunc   ;==>_FindReplace
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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