Click to See Complete Forum and Search --> : VBA - VB.Net - Integrating
dvillecco
Sep 28th, 2004, 11:45 AM
Hi, I need assistance on how I could have VBA currently running in Excel to notify events to a VB.Net system.
VBA code is continuosly processing data. My idea is to modify it in a way that, under given circumstances, it would post/queue something to a VB.Net "listener" which would then take action.
If I am not clear enough, please let me know.
Thanks in advance
Diego
RobDog888
Oct 5th, 2004, 05:31 PM
One way (I'm sure there are a few) would be in VBA to write some
code to output a text file or something to a directory whe
something meets your criteria. Then in VB.NET write some code to
watch this folder for the change event. Then when that happens
you could read in the file, then dispose of it, do something based
on the file contents and wait for the next file.
HTH
dvillecco
Oct 5th, 2004, 06:23 PM
Hi, In the meanwhile, I have been doing some research in the microsoft's knowledge base and, although I have never used it, I thought of the idea of using MSMQ.
DonŽt know yet if this would be the right approach but the problem with text files or that kind of stuff is that, for the problem I need to solve, I will need many many transactions/messages to be sent from VBA to .Net very fast and also to manage a sort of priority message queues.
IŽll keep researching but so far, I find MSMQ the most adequate way to send messages from VBA to be watched by .Net and perform actions.
Would VSTO help in any way for this?
Thanks
Diego
RobDog888
Oct 5th, 2004, 06:42 PM
Since you have allot of transactions you could also use SendMessage
API to your VB.NET application. Easier than message queueing.
You can send the messages to a bunch of different textboxes
or ??? Each for a specific category from your Excel VBA.
dvillecco
Oct 5th, 2004, 07:11 PM
How would that be? I mean, can you give me some sample code as to send a message from VBA using that API?
Thx
RobDog888
Oct 5th, 2004, 08:31 PM
Here are the basic APIs you will need. You may need more, like
for subclassing depending on how your transaction are and
frequency. Its not too hard to setup. Try a search or the API FAQ (http://www.vbforums.com/showthread.php?s=&threadid=213415)
for a better understanding.
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
HTH
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.