2

I am currently trying to automate screenshot grabs from Bloomberg Terminal using DDE within VBA. Currently I have come up with a way to automatically pull screenshots by 'printing' through the Microsoft XPS Document Writer:

Dim ch As Variant
Dim CUSIP As String
CUSIP = Range("B12")

ch = DDEInitiate("winblp", "bbk")
Call DDEExecute(ch, "<blp-1>" & CUSIP & " mtge<GO>")
Call DDEExecute(ch, "<blp-1> DES<Go><print>")
Application.Wait Now + TimeValue("0:00:02")
Application.SendKeys "DES ", False
Application.SendKeys "{enter}", False

Call DDETerminate(ch)  

The code seems to work fine on the first run, but then crashes the developer on each subsequent. Any feedback or further suggestions would be appreciated. Thanks!

user3813682
  • 21
  • 1
  • 2
  • 1
    Interesting. Can you identify which line executes correctly till the crash? That could help isolate the issue. On a perhaps related note, I have found SendKeys to sometimes be unreliable, but that might not have anything to do with this post. – hnk Jul 07 '14 at 21:18
  • I have read elsewhere on forums that after the intial DDE run the DDE channel link is still open. The DDEInitiate line causes the Excel screen to hang after the first run. – user3813682 Jul 09 '14 at 19:12
  • Also, I don't like using sendkeys either, but I have tried multiple work arounds to export a bloomberg screen to an image file and failed. Though flawed this method has yieled the best results thus far. – user3813682 Jul 09 '14 at 19:17

1 Answers1

2

Probably too late but this may help someone as I've had to do this as well. You can just use the <copy> command in your DDE calls and paste it into Word/Excel/Outlook without using send keys:

Call DDEExecute(ch, "<blp-1> <copy>")
ale
  • 6,369
  • 7
  • 55
  • 65
markben151
  • 21
  • 3