I want to generate an event on keyboard button press. On that event, the running vbscript should be closed. I don't want to add any other scripting lanuguage. If anyone has an idea how to do this, please help me.
Here is my code so far:
Set objShell = CreateObject("WScript.Shell")
If(objShell.SendKeys ("{Esc}") == "1")Then
WScript.echo "del pressedd"
End If
This isn't possible in plain VBScript. The best you could do is to periodically query the user. Eg:
Do
' lots of code here...
Loop While MsgBox("Keep going?", vbOKCancel) = vbOK
Related
So I have a really annoying set of forms at work that I have to fill out daily and spend about 20 minutes doing so, I was looking to script this and have a basic sendkeys method that works but I wanted to improve this.
Dim WshShell, objIE, ElementCol
Dim LinkHref
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Webpage Title"
Set objIE = CreateObject("InternetExplorer.Application")
wshShell.AppActivate objIE
Do While objIE.Busy
wscript.sleep 100
Loop
Set ElementCol = objIE.document.getElementsByTagName("a")
For Each Link In ElementCol
If Link.innerHTML = "*Specfic text" Then
Link.Click
Exit For
End If
Next
So I get an error on the Set ElementCol line that says null thats my first issue
For the *specific text is this allowed? Basically I know the text of the links will be Hello and world but could pop in like 1) Hello and 2) World or 1) World 2) Hello
I also want to after the click run a different .vbs script that fills out the form after that .vbs script completes it returns back to this initial page where I want to continue on this script to the next link.
Thanks a ton for any help!
I am trying to run a vbscript that will load up a html page in chrome and then do control+a which will select everything on the page, with the ultimate view to copy it and then paste it into excel.
this my script so far:
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim iURL
Dim objShell
iURL = "C:\Users\Aasfasf\AppData\Local\Temp\TD_80\hpqc\52136023e30\****\121200.html"
set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)
WScript.Sleep 1500
WshShell.SendKeys "^a"
when I run it loads up the html page, but i dont think the control+a command is working as nothing is selected.
Two suggestions:
The focus is probably not on the content in chrome. Try sending a Tab key press a couple of times first to see if that fixes it.
A better approach to this might be to just read the contents of the file, then delete all the markup from the document using regex.
Excel can just load your web page without needing any help from you.
Alt + D, D, W
I am looking to automate our reporting. We currently have 5 Tabs in Firefox that we refer to for reporting. Each Tab has a unique url that changes each morning. We then have to each morning update these URLs (from an excel speadsheet). I would like to automate this. I do have a few constraints on this though. I cannot open a new tab for each new url (so basically it needs to be a url replace in each tab). I have looked into selenium but cannot get it to work
http://www.makeuseof.com/tag/using-vba-to-automate-internet-explorer-sessions-from-an-excel-spreadsheet/
and
http://www.makeuseof.com/tag/how-to-automate-firefox-or-chrome-with-vba-and-selenium/
So I was wondering if it could be done another way either using pure VBA or a batch file?
You need to add a reference to Microsoft Internet Controls and Microsoft Shell Controls and Automation. See screenshot below.
Code:
Sub Work_With_Open_IE_Instance()
Dim objShell As Shell
Dim objIE As InternetExplorer
Dim objWin As Object
Set objShell = New Shell
For Each objWin In objShell.Windows
If TypeName(objWin.Document) = "HTMLDocument" Then
Set objIE = objWin
'~~> This will display the URL of the IE which we will use to bind
Debug.Print objIE.LocationURL
'~~> Example to bind
'~~> Change URL to your existing URL
Select Case objIE.LocationURL
Case "https://www.google.com"
With objIE
.Refresh
'
'~~> Rest of the code
'
End With
Case "http://in.msn.com"
With objIE
.Refresh
'
'~~> Rest of the code
'
End With
End Select
End If
End If
Next objWin
End Sub
The Select Case is just for demonstration purpose. If you want to work with them one after the other then don't use Select Case. Use If/EndIf one after the other.
I have a custom form built within Outlook that sends an email notification any time a change is made. Because of the specifications of the form, I had to add a bit of VBScript (unfortunately) to the form that does the emailing on the closing event of the form.
The form is currently published and works well. The only problem that appears to be cropping up is that I am the only one of the users that use the form that gets prompted with the following dialog:
Nobody else that uses the form is getting the dialog. This dialog box forces you to wait until the progress bar is complted before it "Allow"s you to send the email (about 5 seconds). Is it because I am the publisher? Or is it a client side setting that I am running into? How do I disable this puppy?
In case its relevant heres the source:
Sub SendAttach()
'Open mail, adress, attach report
Dim objOutlk 'Outlook
Dim objMail 'Email item
Dim strMsg
Const olMailItem = 0
'Create a new message
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = Item.UserProperties("Assigned To")
objMail.cc = Item.UserProperties("Bcc")
'Set up Subject Line
objMail.subject = "Work Order Notifications: " & Item.UserProperties("Work Order Number") & " - " & _
Item.UserProperties("Subject") & " Due " & Item.UserProperties("Due Date")
'Add the body
strMsg = Item.UserProperties("Specifications") & vbcrlf
strMsg = strMsg & Item.UserProperties("Constraints")
objMail.body = strMsg
objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
objMail.Send
'Clean up
set objMail = nothing
set objOutlk = nothing
End sub
Security here is not a concern. If somebody has managed to start sending emails from my workstation, I have much bigger problems than email spoofing!
As side note, I couldn't decide if SO or SU was the best place for this question. Please redirect accordingly if necessary.
I ran into this problem a while back whilst trying to accomplish somehting slightly different, but for this purpose is the same. The link HK has provided makes for good reading and helps to understand what's going on, however in the end I chose not to go with any of the options discussed on the page. Instead I kept it simple and decided to fool outlook into thinking I was sending the e-mail rather than an automated process, I did this by replacing the objMail.Send with a SendKeys alternate to mimic myself pressing the send button, bit ugly but worked in my case.
Edit:
You can use this sendkeys statement:
SendKeys "%{s}", 1
This basically calls Alt + S which triggers the outlook send button.
Three options
- Use a pc without the MS Outlook security patch
- Use the redemption ocx (google it up to download)
- Use SMTP instead of outlook
For the second option here an example
Function sendmail2 (sRecipient, sSubject, sMsg, sAttach)
on error resume next
dim SafeItem, oItem
set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
set oItem = oApp.CreateItem(0) 'Create a new message
With SafeItem
.Item = oItem 'set Item property
.Recipients.Add sRecipient
.Recipients.ResolveAll
.Subject = sSubject
.HTMLBody = sMsg
.Send
End With
End Function
I ran into the same problem and because my application runs on Windows 7 I was able to use Windows Mail Client (wlmail.exe) to send emails instead of MS Outlook. With Wlmail, the warning still comes in the default behavior but there is an option to turn off the warning by going to Options > Security tab and once you turn it off the program can send mails without bringing up a pop up.
Another possible workaround is to update the registry setting on your machine.
https://support.microsoft.com/en-gb/help/3189806/a-program-is-trying-to-send-an-e-mail-message-on-your-behalf-warning-i
This link outlines how to identify the relevant registry key and what value should be set. This allows you to override Trust Center settings.
How to perform the Pressing of Enter Action in QTP. I'm selecting a cell and able to set a value ,now I want to press enter key and get the list from that Java Edit box. Which are the different ways I can achieve this?
Use mentioned above Type method: YourObject.Type micReturn
Use SendKeys method:
Function SendKeys(sKey)
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Your browser" ' You may need to activate your browser first
WshShell.SendKeys sKey
wait(1) ' You may need to add some Wait statements around
End Function
In your case it will be
SendKeys "{ENTER}"
See MSDN SendKeys and MSDN AppActivate for more details.
You can either send key (micEnter) through .Type() method of the object or use FireEvent to invoke an event handler directly.
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate
WshShell.SendKeys (ENTER) '--------parenthesis