danwilliams2410

Word Doc creation script is running inconsistently (new user)

2 posts in this topic

The purpose of this script is to create a number of word documents that have a company logo, a unique EAN barcode, and some unique information taken from a spreadsheet. So far I've started writing the script as if to create just one document, however I'm having some issues.

1) The script doesn't seem to like the 'alt' shortcuts in MS Word - it only occasionally works...

2) The script doesn't produce the same result every time it runs - its progress varies every time.

Here is the script:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>
#include <Clipboard.au3>
#include <WinAPIFiles.au3>


Local $ean_number


ShellExecute( "EAN Numbers.xlsx", "", "C:\Users\Dan.Williams\Documents\Label Printing\EAN Numbers", $SHEX_OPEN , "") ;copy ean no
    WinWaitActive("EAN Numbers - Excel")
        Send("^{HOME}")
        Sleep(1000)
        Send("^c")
        Sleep(1000)


$ean_number = _ClipBoard_GetData()
_ClipBoard_Empty()


    Run("C:\Program Files\Microsoft Office 15\root\office15\WINWORD.EXE") ;create word doc
        WinWaitActive("Word")
            Sleep(1000)
            Send("{ENTER}")
        WinWaitActive("Document1 - Word")
            Sleep(1000)
            Send("{CTRLDOWN}")
            Send("s")
            Send("{CTRLUP}")
            Sleep(1000)
            Send("{TAB}")
            Send("{TAB}")
            Sleep(1000)
            Send("{ENTER}")
            Send($ean_number)
            Sleep(1000)


Run("explorer.exe " & "C:\Users\Dan.Williams\Documents\Label Printing\a2a Logo") ;copy logo
    WinWaitActive("a2a Logo")
        Sleep(1000)
        Send("^a")
        Sleep(1000)
        Send("^c")
        Sleep(1000)
    WinClose("a2a Logo") ;close window
    Sleep(1000)


WinActivate($ean_number & " - Word") ;paste and format logo
    WinWaitActive($ean_number & " - Word")
        Sleep(1000)
        Send("^v")
        Sleep(1000)
        Send("+{LEFT}")
        Sleep(1000)
        Send("{LALT}")
        Sleep(1000)
        Send("j")
        Sleep(1000)
        Send("p")
        Sleep(1000)
        Send("w")
        Sleep(1000)
        Send("18{ENTER}")
        Sleep(1000)
        Send("{RIGHT}")
        Sleep(1000)


Run("explorer.exe " & "C:\Users\Dan.Williams\Documents\Label Printing\Artwork") ;copy ean
    WinWaitActive("Artwork")
        Sleep(1000)
        Send("^f")
        Sleep(1000)
        Send($ean_number)
        WinWaitActive($ean_number & " - Search Results in Artwork")
        Send("{TAB 2}")
        Sleep(1000)
        Send("^c")
        Sleep(1000)
    WinClose($ean_number & " - Search Results in Artwork")
    Sleep(1000)


WinActivate($ean_number & " - Word") ;paste and format ean
    WinWaitActive($ean_number & " - Word")
        Sleep(1000)
        Send("^v")
        Sleep(1000)
        Send("+{LEFT}")
            Sleep(1000)
            Send("{LALT}")
            Sleep(1000)
            Send("j")
            Sleep(1000)
            Send("p")
            Sleep(1000)
            Send("w")
            Sleep(250)
            Send(6)
        Send("{ENTER}{RIGHT}")


WinActivate("EAN Numbers - Excel") ;copy TP
    WinWaitActive("EAN Numbers - Excel")
        Sleep(1000)
        Send("{TAB}")
        Send("{SHIFTDOWN}")
        Send("{RIGHT 2}")
        Send("{SHIFTUP}")
        Send("^c")


WinActivate($ean_number & " - Word") ;paste TP
    WinWaitActive($ean_number & " - Word")
        Sleep(1000)
        Send("^v")
        Sleep(1000)
        Send("{ENTER}")


WinActivate("EAN Numbers - Excel") ;copy Bosal
    WinWaitActive("EAN Numbers - Excel")
        Sleep(1000)
        Send("{TAB}")
        Send("{SHIFTDOWN}")
        Send("{RIGHT 2}")
        Send("{SHIFTUP}")
        Send("^c")


WinActivate($ean_number & " - Word") ;paste Bosal
    WinWaitActive($ean_number & " - Word")
        Sleep(1000)
        Send("^v")
        Sleep(1000)
        Send("{ENTER}")


WinActivate("EAN Numbers - Excel") ;copy BM
    WinWaitActive("EAN Numbers - Excel")
        Sleep(1000)
        Send("{TAB}")
        Send("{SHIFTDOWN}")
        Send("{RIGHT 2}")
        Send("{SHIFTUP}")
        Send("^c")
    WinClose("EAN Numbers - Excel")


WinActivate($ean_number & " - Word") ;paste BM
    WinWaitActive($ean_number & " - Word")
        Sleep(1000)
        Send("^v")
        Sleep(1000)
        Send("{ENTER}")
        Send("^s")

I'm new to this, I've only done bits of SQL before, no other coding. Any help/advice would be appreciated.

Share this post


Link to post
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