Jump to content

Script doesn't work in Microsoft Office


RandomSF
 Share

Recommended Posts

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?

Link to comment
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!
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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]

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...