SendKeys open application

Hi! I try to open a program from a macro in Excel and login (the Bloomberg professional, (not the website)) using SendKeys. With some help from other programmers I got the following code. It does not work at all though and I am lost. Can someone please help me with this My problems are:

1) I get error on the WaitFor …line. ”Sub or Function has not been defined”

2) If I delete the WairFor line I get error on the AppActivate("1-BLOOMBERG") line. “Illegal procedure call or argument”

Sub bbg_login()
AppActivate("1-BLOOMBERG")
Application.SendKeys "{BREAK}",false
WaitFor timevalue("00:00:01")
Application.SendKeys "user_Name", false
Application.SendKeys "{TAB}", false
Application.SendKeys "password", false
Application.SendKeys "~", false
End Sub

Any help appreciated!



Answer this question

SendKeys open application

  • Jeff Walsh

    Hello duck thing! Thank you very much for good answer! I do not know if you are familiar with the Bloomberg professional (the program and not the website). My problem is not that I do not have a "1-BLOOMBERG"-window. However your code seems very good and can perhaps ensure a better way to login. I am not sure what you are referring to when you say the Windows API (sic!). I do not know very much about programming but there is a Windows API in Bloomberg (or something like that). Can I use your code in a macro and what kind of declarations do I have to make I know I seem like I do not have a clue but the problem is that I really do not and no one else around here have any clue either so I cannot get any help whatsoever from anyone (except on these forums). Thus, I would very much appreciate any assistance that anyone can give me! Oh duck thing please tell me if you are familiar with the Bloomberg or not. There seems to be programs that do not support SendKeys and other forms of automatic login and I do not know if Bloomberg is of that kind. Thank you all very much!
  • Robert Peszek

    Hello Anders,

    Haven't forgotten about this. I just don't know how I can help you without being at the computer and seeing the system at work. By the sounds of things Excel talks to the Bloomberg application. It reads that the Bloomberg application has all the login code and data querying methods and Excel just send the data the application needs to query online data, returning the information back to Excel. .

    Bottom line, I have no idea how I can help you without seeing the whole system working.



  • Goat Spirit

    Hello Derek Smyth! Thank you very much for your answer! The info that is publically avaliable concerning the Bloomberg can be find on the website http://about.bloomberg.com/software/index.html. If you have access to the program you can find out more. There is a login function if you have TSAPI (a Bloomberg application for traders but I dont have that) but I think that is just some network connection or something. I realize that this is not much info to give but I am really lost here. The thing is that the Bloomberg is very well integrated with office apllications e.g. Excel and Access. There are add-ins for Excel so it is very easy to download data from Bloomberg to Excel. However how to automatically login to the Bloomberg using a VBA macro in Excel (or any other way that is fairly easy and does not require the purchase of new software) is a different story. All documentation that I have found concerns how to download data to Excel, which is very easy. Eventhough the Bloomberg costs like $1700/month they do not offer any help in this field. I suspect it is for a reason e.g. fear of automatic login with the help of a program may faciliate hacking their products or something. Any help would be very much appreciated, as you can see I am no computer wiz so I really have a hard time figuring out how to do this! Thanks alot in advance!
  • ratslav

    Hello AndersBank,

    The WaitFor() method isn't a part of Excel (which I think your coding in), use the Application.Wait method instead.

    I think the WaitFor() method just pauses for a second or two to make sure the login screen has time to become active.

    This example displays a message indicating whether 10 seconds have passed.

    If Application.Wait(Now + TimeValue("0:00:10")) Then
      MsgBox "Time expired"
    End If


  • Dave Reinhart

    Anders,

    I can see you've been having a few problems for a while getting this to work.

    Are your using the Bloomberg Excel addin ... Is there a play button ... when you press this does it prompt you to supply a username and password and once you ok that does it download the data. If this is not correct let me know what the steps you take to download the data.

    Can you do something can you open the Visual Basic Editor in Excel... Tools->Macro->Visual Basic Editor... in the Project Explorer you should see the Bloomberg Addin, can you double click and open it, does it prompt you for a password

    can you also select from the Visual Basic editor Tools->References in the toolbar. Can you get me a screen dump of this dialog, if not what files are being referenced

    Somewhere there is code that performs the login, we need to find this code, it has to be somewhere. If the code is accessible through the addin then that would be good, if not then I don't want to think about it.

    Let me know the answers to these questions.



  • Kapalic

    Are you familiar with the Windows API If so, I've found that it's a much better way to do things like this. Assuming you've Declared the appropriate API functions, you can do this:

    Sub bbg_login()

    Dim hBBGWnd As Long

    hBBGWnd = FindWindow(vbNullString, "1-BLOOMBERG")

    If hBBGWnd = 0 Then

    MsgBox "Error - can't find window."

    Exit Sub

    End If

    ShowWindow hBBGWnd, SW_SHOWNORMAL [or use &H1 if you don't feel like defining this]

    SendKeys [insert your command string here], True

    End Sub

    What I think might be happening is that when you call AppActivate, you're providing the "wrong" information. If no window is titled "1-BLOOMBERG", your code will cause a runtime error because it can't find a window with that title. This is why I prefer using the API function FindWindow: you can specify the name of the window class without knowing its title, or vice versa. Anyway, if you use the above code and the "Error - can't find window." messagebox comes up when you run the code, then you don't have a window titled "1-BLOOMBERG" running. In that case, I'd suggest using EnumWindows to help you figure out what the application's main window's title is (or, since you could presumably be running more than one instance of the application, figure out the window's class name and use that to activate it).



  • Marcel leclerc

    AndersBank,

    API stands for Application Programming Interface, it's a name thats used to encompass all the programming objects/functions etc that you need to do a task. For example Excel, all the code you write in Excel uses an Excel API, the VLOOKUP the Workbook.Save(), all the built in programming functions of Excel are called the Excel API.

    The Windows API is the same except it's programming functions that Windows makes available.

    The reason I'm posting this is if Bloomberg (I know who you mean now) has an API then it's very likely that it will have programming functions you can use to do common Bloomberg tasks, like for example login.

    Where did you get the Bloomberg API Do you have any information on the API that people here can look at

    If I can get more information on the API I'll have a better idea on what your able to do.



  • Paul Mitton

    Hello! Thank you very much for your patient help! Let me try to answer your questions along with some clarifications.

    I download the data in the following way. In my spreadsheet I have a button connected to a macro. In that macro I contact the Bloomberg and open a DDE connection using this code:

    channelNumber = Application.DDEInitiate(app:="BLP", topic:="S")

    then comes some other code that get some data from the spreadsheet and then I make a call to the Bloomberg to get data:

    BloomQuery = " ' " & ISIN & Corp, [RTG_SP] ' "

    returnList = Application.DDERequest(channelNumber, BloomQuery)

    This all works fine when the Bloomberg professional is open and you have loged in. If that is not the case the macro cannot download data. I guess it is here in the macro that you must have some code that lets you log in to the Bloomberg if possible.

    Thus to answer your first question I do not really use the BBG Excel addin. Howver if I open the VB editor I find lots of Bloomberg macros. One of them suggests that it handles the login cause it is named "Bloomberg Server Connect". However the code is not avaliable without a password (that I do not have).

    I am sorry if I have not answered all your questions but someone else needed to use the Bloomberg so that was all the info I could get. Hope that will give you some idea. Thanks again for your kind help!


  • SendKeys open application