Jump to content

Pre-Newbie Question


Recommended Posts

I somehow found my way here because I'm looking for a substitute for the infamously unstable VBS Sendkeys command.

I'm wondering if I can develop an alternative in Autoit that could be called from within my VBA script? Can someone tell me if this is possible (and fairly painless?) muttley Thanks - TaDuh

Link to comment
Share on other sites

I somehow found my way here because I'm looking for a substitute for the infamously unstable VBS Sendkeys command.

I'm wondering if I can develop an alternative in Autoit that could be called from within my VBA script? Can someone tell me if this is possible (and fairly painless?) muttley Thanks - TaDuh

So basically you want to be able to send keys from AutoIt using another app/script?

Create an EXE from AutoIt with something like:

WinWaitActive("Your Title")
Send("This is a string of text")

Tools>Compile (Ctrl-F7)

Create an EXE. You should be able to call the EXE from anything else.

Link to comment
Share on other sites

I somehow found my way here because I'm looking for a substitute for the infamously unstable VBS Sendkeys command.

I'm wondering if I can develop an alternative in Autoit that could be called from within my VBA script? Can someone tell me if this is possible (and fairly painless?) muttley Thanks - TaDuh

I have succesfully used several compiled AutoIt scripts called from within VBA modules in Excel & Word.

You can pass command line parameters to the AutoIt script on launch and can have AutoIt hand information back via Exit code or writing to ini files for your VBA to read.

Link to comment
Share on other sites

I have succesfully used several compiled AutoIt scripts called from within VBA modules in Excel & Word.

You can pass command line parameters to the AutoIt script on launch and can have AutoIt hand information back via Exit code or writing to ini files for your VBA to read.

What is the VBA syntax for calling your AutoIt script?

Link to comment
Share on other sites

What is the VBA syntax for calling your AutoIt script?

In this example, my compiled AutoIt exe is called "MakePDF" and I am passing 3 command line parameters to it:

  • sourceName: the source document
  • shortPdfName: the filename of the PDF document
  • longPdfName: the full path & file name of the pdf file

PDFMe = Shell("C:\makepdf\BIN\MakePDF.exe " & _
        Chr(34) & sourceName & Chr(34) & _
        " " & _
        Chr(34) & longPdfName & Chr(34) & _
        " " & _
        Chr(34) & shortPdfName & Chr(34), 1)
Link to comment
Share on other sites

In this example, my compiled AutoIt exe is called "MakePDF" and I am passing 3 command line parameters to it:

  • sourceName: the source document
  • shortPdfName: the filename of the PDF document
  • longPdfName: the full path & file name of the pdf file

PDFMe = Shell("C:\makepdf\BIN\MakePDF.exe " & _
        Chr(34) & sourceName & Chr(34) & _
        " " & _
        Chr(34) & longPdfName & Chr(34) & _
        " " & _
        Chr(34) & shortPdfName & Chr(34), 1)

Thanks ResNullius - I appreciate it! What do the Chr(34) characters translate to? Also, what does the

Link to comment
Share on other sites

Thanks ResNullius - I appreciate it! What do the Chr(34) characters translate to? Also, what does the

Chr(34) is the number 4 (four). You can check this in an ascii table, which can also be found in SciTe's help. "

This is what it does.
Link to comment
Share on other sites

Thanks ResNullius - I appreciate it! What do the Chr(34) characters translate to? Also, what does the

Chr(34) is the number 4 (four). You can check this in an ascii table, which can also be found in SciTe's help. "

This is what it does.
CHR(34) is not the number 4, it is a quotation mark: "

(@Kiti: the number 4 has a hex value of 34, but an ascii value of 52 !)

They are there to "wrap" the variables as they might have spaces in them (like in the long file name that includes the path) and the only way to pass a command line variable with spaces in windows (most of the time) is by enclosing it in quotes. Otherwise it gets broken up at each space:

eg: C:\My Pdfs\Work\A long pdf name.pdf passed without quotes to the program would be seen not as one command line parameter but as 5:

  • C:\My
  • Pdfs\Work\A
  • long
  • pdf
  • name.pdf
So I make sure it gets sent as "C:\My Pdfs\Work\A long pdf name.pdf".

There are other ways of having your program recieve command line parameters (i.e.: switches) such that you don't have to wrap with quotes, but that adds another layer of complexity to your AutoIt program.

PS: Kiti is right about the tags, they are used when posting to offset the text into a "code" highlighted area.

For instance

[ code ]If that then

do this

EndIf

[ /code ]

becomes (if you take out the spaces around the words in the square brackets)

If that then
  do this
EndIf

Eaiser to read and see where the code starts and stops!

Edit: hit the "add reply button instead of "preview post" before I was done!

Edited by ResNullius
Link to comment
Share on other sites

CHR(34) is not the number 4, it is a quotation mark: "

(@Kiti: the number 4 has a hex value of 34, but an ascii value of 52 !)

They are there to "wrap" the variables as they might have spaces in them (like in the long file name that includes the path) and the only way to pass a command line variable with spaces in windows (most of the time) is by enclosing it in quotes. Otherwise it gets broken up at each space:

eg: C:\My Pdfs\Work\A long pdf name.pdf passed without quotes to the program would be seen not as one command line parameter but as 5:

  • C:\My
  • Pdfs\Work\A
  • long
  • pdf
  • name.pdf
So I make sure it gets sent as "C:\My Pdfs\Work\A long pdf name.pdf".

There are other ways of having your program recieve command line parameters (i.e.: switches) such that you don't have to wrap with quotes, but that adds another layer of complexity to your AutoIt program.

PS: Kiti is right about the tags, they are used when posting to offset the text into a "code" highlighted area.

For instance

[ code ]If that then

do this

EndIf

[ /code ]

becomes (if you take out the spaces around the words in the square brackets)

If that then
  do this
EndIf

Eaiser to read and see where the code starts and stops!

Edit: hit the "add reply button instead of "preview post" before I was done!

Thanks, Resnullius - taDuh
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...