Code that will allow me to Left mouse click, I can only use Notepad to write the code and java is installed - vbscript

I'm trying to write a script in VBScript that executes a series of events and one of them includes a left mouse click and release.
I know that I can't use VBScript in order to do the left mouse click and I can't install any software. I am only able to use Notepad in order to do all the code writing. I do have Microsoft word as well but I don't know if you can use that to write any code.
Is there a way for me to write some simple code in another language that allows me to left mouse click and release? I'm then planning on importing this code into my VBScript and continue on from there.
What I have so far:
Option Explicit
Dim Excel, x, y
Dim s
Set Excel = WScript.CreateObject("Excel.Application")
x = "10"
y = "10"
Excel.ExecuteExcel4Macro ( _
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")
WScript.Sleep (1000)
WScript.Sleep (1000)
WScript.Echo "Stop Script, Test test"
Thanks for reading!

Related

There is another way do Copy and Paste in VBS or BAT?

I was trying to automatize some repeated fill forms that I do in my job. I automate a lot of in VBA Excel, and I wanted to do with VBS too, but the company's computer doesn't work "^{C}", eather "%{TAB}".
In resume, ALT + or CTRL+ doesn't has the common response and a lot of functions are blocked...
There is another way to Change Window and Copy/Paste?
I found the problem:
.vbs has a lot of bugs in the blocked computer.
Ctrl + C or V works better as lower case: "^{c}" & "^{v}"
And the % + something doesn't work in any way.
So worked like this way for me:
Dim WS
set WS = CreateObject("WScript.Shell")
WS.AppActivate "Protocolos - Internet Explorer" ' name of the sheet
CScript.Sleep 100
WS.SendKeys "^{c}"
CScript.Quit

Excel VBA to get UNC from cell and open it in explorer.exe

I have a file with a list of PC hostnames I want to be able to connect to the C drive of a specific one by clicking in a cell or button or something.
Let's say I currently have the hostname in Column A. I use CONCATENATE to turn it into a proper network path \\hostname\C$ and put that in Column B.
Now how can I make it so I can just click on the cell in column B to open that location in explorer.exe?
I have 450 PCs so i need to be able to specify the range, feed the network path into VBA and then open that in explorer.exe
does this make any sense? :P
Would really, really appreciate any help. Thanks.
Wrap the concatenated value in a "Hyperlink()". From then on it is clickable and it will open the explorer.
=HYPERLINK(CONCATENATE("\\";A1;"\C$");A1)
Or you put this code in your Worksheet code pane and double click the cells, where your links stand. But then you mustnt use it in combination with HYPERLINK.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 2 Then Exit Sub
Dim sh As Object
Set sh = CreateObject("Wscript.Shell")
sh.Run ("explorer " & Target.Value)
Cancel = True
End Sub

Set cliclick co-ordinates relevant to UI element in AppleScript

Firstly I have only been using AppleScript for the last couple of days, so am really new to it and have no real other scripting knowledge, so forgive me if this comes across as something trivial or I ask lots of follow up questions.
I have an element that I would like to right click on using cliclick, but the location of the element moves depending upon other windows and sidebars being open
I would like to use
position of button 1
to return the correct co-ordinates so I would like to be able to use maths to add to the X,Y co-ordinates in cliclick so it would be something like this
position of button 1
do shell script "../cliclick c:x+25,y+5"
is this possible or is it something that I will have to using another language? I am thinking the final project will be compiled into an application using Xcode and will be hiring someone for this, am just trying to make their life as easy as possible beforehand.
Ok after a bit of fumbling around the internet I found something else and then fiddled with it a bit and finally solved the above using the following
tell UI element 1 of toolbar 1 of toolbar 3 of the front window
set p to position
set x to item 1 of p
set y to item 2 of p
end tell
do shell script "/Users/dave/_app-dev/cliclick c:" & x & "," & y & ""
Just incase anyone else looks for it here is the answer
A more compact equivalent code:
set {x, y} to position of button 1 of toolbar 1 of toolbar 3 of window 1
do shell script "/Users/dave/_app-dev/cliclick c:" & x & "," & y & ""

shift + arrow key

Hi I want to automate the process of selecting some lines from "Personal Communications iSeries Access for Windows".
http://i.stack.imgur.com/doshI.jpg
Manually this can be accomplished by:-
1. selecting from mouse (Drag mouse holding LEFT mouse button)
2. Position the cursor and press SHIFT+ARROW keys(UP/DOWN/LEFT/RIGHT).
I tried to do it with VBScript in following way:-
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{RIGHT 5}" 'Position the cursor
WshShell.SendKeys "+{RIGHT 5}" 'Sending SHIFT+Right Arrow five times
But the code for shift+RIGHT Arrow Keys is not working for me. It is writing 66666. Similarly for WshShell.SendKeys "+{LEFT 5}"I am getting 44444 as output.
These VBScript sendkeys commands are working fine for other windows applications(like MS Word, Notepad).
Any idea how to proceed?
Try turning NumLock on, then use the arrow keys on the numbers 4 and 6.

Using AppActivate and Sendkeys in VBA shell command

I want to switch back and forth between application with the shell command in VBA.
I am using SendKeys to do stuff in process A then move to process B, then to process A then process B. It works fine for the first iteration. When I use AppActivate to go back to process B, it actually does switch focus back to process B. HOWEVER, it ignores subsequent commands from SendKeys.
Example code:
Sub pastePDF2TXT_v3(pdfName As String, txtName As String)
Dim acrobatID
Dim acrobatInvokeCmd As String
Dim acrobatLocation As String
Dim notepadID
Dim acrobatID2
Dim notepadID2
Debug.Print "here"
acrobatLocation = "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe"
acrobatInvokeCmd = acrobatLocation & " " & pdfName
acrobatID = Shell(acrobatInvokeCmd, 1)
AppActivate acrobatID
SendKeys "^a", True '^A selects everything already in the pdf file.
SendKeys "^c", True '^C copies the selection to the clipboard.
notepadID = Shell("NOTEPAD.EXE " & txtName, 1) ' invoke notepad on the text file.
AppActivate notepadID ' set the new app as teh active task.
SendKeys "^a", True '^A selects everything already in the text file.
SendKeys "^v", True '^V pastes the new stuff over the top of the old text file (deleting the old stuff)
SendKeys "%{END}", True ' makre sure last line of text file
SendKeys "{ENTER}", True
AppActivate acrobatID ' NOTE: APPEARS TO WORK UP TO THIS POINT.
SendKeys "{ENTER}", True ' NOTE: SECOND APP IGNORES SUBSEQUENT COMMANDS FROM HERE DOWN.
SendKeys "^a", True '^A selects everything already in the pdf file.
SendKeys "^c", True '^C copies the selection to the clipboard.
SendKeys "%f", True 'alt f, x to exit Notepad.exe
SendKeys "x", True
'acrobatID.Quit
Debug.Print "start second"
AppActivate notepadID ' set the new app as teh active task.
SendKeys "%{END}", True 'Go to end of text file.
SendKeys "^v", True '^V pastes the new stuff at end of file.
SendKeys "{ENTER}", True
SendKeys "^s", True
SendKeys "%f", True 'alt f, x to exit Notepad.exe
SendKeys "x", True
notepadID.Quit
acrobatID.Quit
End Sub
I know this question is old, but I have run into this same problem, but I don't think the answer that was chosen is the correct one.
When you call AppActivate, the script goes on halt, waiting for the target application to terminate. After the application is terminated, the script continues. I see no solution to this issue.
EDIT:
I use a batch-file to call CSCRIPT for the AppActivate command, and I notice you are strictly using a VBS file. Try calling CMD as a new window and pass CSCRIPT //NoLogo //B WScript.CreateObject("WSCript.shell").AppActivate("Window Name") as the argument, and see if that bypasses the issue.
Similarly, I was trying to use AppActivate on a pdf document I had opened with a shell command so that I could use SendKeys on it. It would always generate Run Time Error '5'. My solution, eventually was to NOT use AppActivate at all, in fact opening the document brings it to the forefront anyway. The problem is that the SendKeys statement executes immediately after the shell command but the pdf needs a second or two to open up. My solution is to pause the code for a couple seconds before excuting the sendkeys statement.
I used a time delay curtosy of pootle flump. Check out the thread here:
http://www.dbforums.com/microsoft-access/1219379-time-delay-vba.html
After hours of research on various forums, I could figure out that I wont be able to use Adobe library objects and functions with Adobe Reader. The only viable option left was to use Shell Commands to use "save as text" option available in the Adobe Reader's file menu. The shortcut key is Alt+f+a+x+s. I implemented these in the below code which worked perfectly, although I was required to insert delays in some steps.
Sub SavePDFasText()
Dim AdobeReaderPath As String
Dim PdfFilePath As String
Dim PDFid, NotepdId As Double
AdobeReaderPath = "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"
PdfFilePath = "D:\PowerGenMacro\opm_11.pdf"
PDFid = Shell(AdobeReaderPath & " " & PdfFilePath, vbNormalFocus)
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
'Alt+f+a+x is required to save the pdf as text in the adobe reader
SendKeys "%(FAX)", True
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 2)
SendKeys "%S", True
SendKeys "^q", True
End Sub
This might be more of a comment than an answer, but I don't seem to be allowed to "comment", so...
It's amazing you've gotten as far as you did. Chances are, you're never going to be able to make this work reliably -- period. As soon as you do make it work, something will change about how the Acrobat UI behaves in a future release, or Windows will make another change to the rules for what things can send events to what other things, and then you're hosed again.
What you are probably running into in this case is Windows trying to prevent an application stealing the focus from another when a user is apparently busy interacting with the first one. You see the same kinds of problems trying to do things like have a button in one application write data to a temporary file and open MS Word to edit it. Windows prevents the focus from transferring away from the current app and over to MS Word because you just clicked a button in the current app.
So -- instead of trying to solve this impossible technical issue, let's take a step back and ask what you were originally hoping to accomplish by doing all of this. In that way, perhaps, we can get you where you're trying to go :)
Try
sendkeys "%{tab}"
to switch windows
but then keep only 2 active windows.
or try
appactivate only after sendkeys {Tab} so that text entry box is not selected before switchibg windows cmd.
or try
try appactivate window name, 1
then sleep 2000 °to allow time to bring that window into focus
You forgot to add "DoEvents" between each sendkeys and kind of delay/wait period, to give it some time to execute.

Resources