Sign in to follow this  
Followers 0
RandomSF

Script doesn't work in Microsoft Office

7 posts in this topic

I have a simple title case script that works everywhere except MS Access and Word.

Sleep(10)
Send("^c") 
$x=clipget()
$rez = Titlecase($x)
ClipPut($rez)
Send("^v")

If I highlight text in any other app, press the shortcut key sequence to fire the AutoIT script, it works fine. In Access and Word nothing happens. Adding a msgbox to see what's in the clipboard brings up an error showing that nothing is there.

Has anyone experienced this, and more importantly, does anyone have a fix?

Share this post


Link to post
Share on other sites



Perhaps the keyboard shortcut already means something in Word and Access. Try a hotkey such as PAUSE that has a very low chance of conflicting.

; Example
HotKeySet("{PAUSE}", "Upper")
While 1
    Sleep(100)
WEnd

Func Upper()
    Sleep(10)
    Send("^c")
    $x=clipget()
    $rez = StringUpper($x)
    ClipPut($rez)
    Send("^v")
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

I was careful to pick something that Access doesn't use (this works on my previous computer and other computers in the office). I even tried a different combination and it still doesn't work.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think I may not have stated myself clearly. The hotkey I am talking about fires the Windows Shortcut that points at the AutoIt script (EXE actually). The hotkey is not part of the AutoIt script itself.

The odd thing about this is that it works on my previous computer. Both machines run Windows XP, Office 2003, same SPs.

If I copy the text to the clipboard first manually, then run the macro via the Windows Shortcut hotkey, then paste manually, it works in Office. In other programs, the Copy and Paste functions within the AutoIt macro are sufficient.

Still baffled.

Scott

Edited by RandomSF

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this:

Sleep(50)
Send("^c")
Sleep(50)
$x = ClipGet()
Sleep(50)
$rez = Titlecase ($x)
Sleep(50)
ClipPut($rez)
Sleep(50)
Send("^v")

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

That fixed it. Many thanks. :o (I can hear the wicked witch saying, "Sleeeeep, sleeeeeeep.")

edit: Actually, I only needed the Sleep before the Cut and Paste functions

Sleep(50)
Send("^c")
$x = ClipGet()
$rez = Titlecase ($x)
ClipPut($rez)
Sleep(50)
Send("^v")

Could this need for extra sleep time be because the CPU is very fast relative to the previous machine?

Edited by RandomSF

Share this post


Link to post
Share on other sites

...Could this need for extra sleep time be because the CPU is very fast relative to the previous machine?

This has been discussed several times - with no hard conclusion as to why sleeps are needed around clipboard operations on some computers. Best guess was when the clipboard contains large amounts of data - like an image - it just takes a while to clear that out and make room for what control-c wants to put in there.

I would think that you would need the sleep after the send of control-c --- before the clipget operation... but you decide.

I've also used a little loop like this:

While 1
    ClipPut ("")
    Sleep (100)
    $junk = ClipGet ()
    If $junk = "" Then ExitLoop
WEnd
to clear the clipboard before using it... you could speed it up.

[size="1"][font="Arial"].[u].[/u][/font][/size]

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
Sign in to follow this  
Followers 0