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!

SendKeys open application
Ben Vanik
Stigern
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.
EmekaAwagu
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.
LTD
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.
Sam Hobbs
Dilip M
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.
PaulSw
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!
x868
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).