Sending Multiple Words to Another Program - vb.net

How would I output a sentence with VB.NET?
Example: Your program and Internet Explorer are open, your program outputs "http://stackoverflow.com" and presses "{ENTER}", and it will go to the page.
Example: An auto-talking bot for MSN.

If you mean "send a string to a running program", I think you're looking for SendKeys
Edit
SendKeys takes a string argument (that's why it's named SendKeys, not SendKey), so yes, you can send "sentences".

Related

Save a Form as a Report using VBA

In MS Access it's possible to convert a Form to a Report using the "Save Object As" functionality (Office Button -> Save As -> Save Object As "Save the current database object as a new object").
I'd like to have the same functionality using VBA but it seems to me that none of the following relevant DoCmd methods are suitable CopyObject, OutputTo, Save, TransferDatabase.
I was unable to find any useful information, except a blog post in which a code sample is provided using the SendKeys statement, but it seems not working.
Any advice?
It is not possible to convert a form to a report using VBA. Even using Sendkeys (which really should be avoided as there is a potential for the wrong application to get the keypresses instead) is not an effective method, as some controls don't get converted correctly.
Instead, you should be designing a report from scratch, with the required headers/sorting/grouping - it will look far better.
Regards,
Thanks to some tips from MajP on an access-programmers forum post, I found a way that is suitable for my needs, although it uses the sendkey function:
strFormName = "formname"
strReportName = "reportname"
DoCmd.SelectObject acForm, strFormName, True
SendKeys strReportName & "~"
RunCommand acCmdSaveAsReport
strFormName must contain the name of the Form to be saved as a Report whose name must be contained in strReportName.

Interaction with .bat file in VBA

I am interacting with a .bat file launched in my VBA code. The shell is open and I managed to send a few commands however some other commands fail like F9, DOWN and UP.
Here is my chunk of code :
Sub OpenBrice()
Path = "F:\Brice\valpp"
ChDir Path
Shell Path & "\Brice.bat", vbNormalFocus
'Wait during opening BRICE
Wait (2)
'PASS
SendKeys "123"
Wait (1)
'Press Enter:
SendKeys "~"
Wait (1)
'Update current date
SendKeys "O"
Wait (1)
SendKeys "F"
Wait (1)
SendKeys (Format(Now(), "ddmmyy"))
Wait (1)
SendKeys "{ESC}"
Wait (2)
SendKeys "{F9}"
The problem happens on the last line, {F9} doesn't work, as well for {DOWN} or {UP}..
Further in the code, the line : SendKeys "{F8}" works perfectly...
I suspect a bad configuration of the shell or something similar ? Thanks a lot!
P.S : I am just testing some code, I know that I should declare all my variable and use Option Explicit

VBA code to pass username & password

I'm trying to update some data into a SharePoint document and while trying this in local environment I do not face any issue.
But when I try to do the same in virtual desktop, I couldn't make it. I'm being populated with Windows Alert to key-in username & password. I've tried using 'SendKeys' for this scenario, but it doesn't make sense.
....
SendKeys "abc\ATX123",5
SendKeys "Password1",5
SendKeys "{ENTER}",5
....
This snippet is just passing 'ENTER' without entering ID & Pwd. Can anyone suggest me some possible solution, please?
Finally, I've found a way to achieve this requirement,,,,, bit indirect, but that was the only way I could find at the end.
What I did is simple - just created one windows scripted file 'Logon.vbs' to handle that popup screen and called the vbs in VBA.
Refer to the sample below, if you're looking for something like this:
Windows Script:
'Creating an script object
Set oWSH = WScript.CreateObject("WScript.Shell")
'Activating alert screen
oWSH.AppActivate ("Windows Security")
'Passing the value UserName/UserID
oWSH.SendKeys "USERNAME" 'ensure to complete the username with apropriate domain e.g., abc/A123456
'Changing the focus to password textbox
oWSH.SendKeys "{TAB}"
'Passing the value password
oWSH.SendKeys "PASSWORD"
'Clicking enter to complete the screen
oWSH.SendKeys "{ENTER}"
'Releasing the script object
Set oWSH = Nothing
VBA code to call the VBS script - Logon.vbs:
Shell "WScript C:\Users\ABC\Desktop\Logon.vbs", vbNormalFocus
First of all you'll want to SendKeys "yourString", Boolean. As I know the SendKeys command wants a True or a False as second input.
You could also try "tabbing" from a field to another:
SendKeys "abc\ATX123", True
SendKeys "{TAB}", True
SendKeys "Password1", True
SendKeys "{ENTER}", True
if the first one didn't get get written, maybe the focus is on another component of the userform. Try "tabbing" to find out if your "Username" textbox is yet activated as the UserForm appears. In case it isn't you could also try to set some focus

Console application - first Message Box is not focused

I am in the process of developing a VB.Net console app to get ID & password from users and should pop a message when invalid ID or password is entered, but I am stuck with a peculiar behavior observed while using Message box in console app. When the first message box is shown, its Out-Of-Focus & we explicitly need to bring the message box to focus. But the next subsequent message boxes are In-Focus.
Below is just the sample code.
Sub Main()
Start:
Console.WriteLine("Press Enter")
Console.ReadLine()
MsgBox("Good Day")
GoTo Start
End Sub
Just want to know why such thing is happening & what should be done so the first message box also will be In-Focus.?
You can use the MessageBoxOptions.ServiceNotification to show the dialog on top.
This is converted from a C# application, so not exactly sure if this is correct VB.NET (it should be though):
MsgBox( "Good Day"
, ""
, MessageBoxButtons.OK
, MessageBoxIcon.Asterisk
, MessageBoxDefaultButton.Button1
, MessageBoxOptions.ServiceNotification
)
But note this:
You shouldn't use a MessageBox inside a Console application. These are just two different worlds.
To explain why:
What do you expect when you run this application remotely using the console? There is no way to show that messagebox then. Use Console.WriteLine, but with different coloring if you want to show something is in error, or a warning, or something good.

Stop vbscript deactivating current window when running?

I'm trying to write a simple script to fill in login details on a program that requires signing in using a keyboard shortcut.
set wshshell = wscript.CreateObject("wscript.shell")
WshShell.SendKeys "username{tab}passowrd{enter}"
This works as desired on my work computer (xp) but on my home computer (windows 8) the keyboard shortcut deactivates the current window so that the details are not entered.
Any help would be greatly appreciated.
You may want to look into the shell's AppActivate method. You could write something like this:
boolSuccess = False
do until boolSuccess = True
boolSuccess = WshShell.AppActivate("AppName")
WshShell.sleep 500
loop
WshShell.SendKeys "username{tab}password{enter}"
This will move the focus to your target app, and then send the keys. The tragically kludgey part is that you may need that 'sleep' between the AppActivate and the SendKeys to be sure that your target app has time to receive the focus.