Java and VBA Communication practice __java

Source: Internet
Author: User
1. DDE (Dynamic Data exchange) mode
VBA has DDE capabilities and Java does not. Online search, several companies have developed this kind of library, can make Java with DDE ability.
(1) Javadde-nevaobject:
Http://www.nevaobject.com/_docs/_javadde/JavaDde.pdf
(2) Winpack-jniwrapper:
Http://www.jniwrapper.com/pages/winpack/overview
The two-class libraries are known to be strong, but they all require payment and have no research. Play Winpack demo, almost all Windows tools, such as viewing the hard disk, network connectivity, user management, etc., can be used in its class library using the Java language to wrap.

2. Com DLL Mode
This approach is theoretically possible, but Excel files run around with DLLs, which is always a shame.
(1) The method provided by Sun ActiveX Bridge-sun. See the following page specifically.
Http://java.sun.com/j2se/1.4.2/docs/guide/beans/axbridge/developerguide/index.html
Brief usage:
-1. Write a Java bean, and use the Java ActiveX Bridge to create DLL. CODE:[Copy to Clipboard] C:/Program Files/java/j2re1.4.2/axbridge/bin>c:/j2sdk1.4.2/bin/packager-clsid { d824b185-ae3c-11d6-abf5-00b0d07b8581}-out. -reg F:/excelvba/excelvba.jar jp.co.esm.pmt.pmtbean-2. Write the VBA in Excel.
(2) J-integra offers two solutions.
Pre-binding and late binding. Late binding no need to know the Java object information of the communication, after registering the Java object to the virtual machine (using the J-integra tool), you can dynamically find the object at run time.
Early binding is faster than late binding, but registers the JVM to VB project before compiling.
Pre-binding method: Http://j-integra.intrinsyc.com/support/com/doc/javafromcom/vb2javaeb.html
Late-bound method: http://j-integra.intrinsyc.com/support/com/doc/javafromcom/vb2javalb.html
(3) Microsoft tools Microsoft SDK for Java
However, due to Microsoft and Sun's lawsuit, on the Microsoft website has not been able to download the tool.
Homepage:http://www.microsoft.com/mscorp/java


3. Socket Communication
Using socket communication, Java as the server side, VBA as the client. In this case, Java is not a relationship.
Java server-side programs are relatively good to write. The key is the VBA client.
(1) using the Wsock control is of course the simplest, but our code cannot have windows, and we cannot use Wsock. And my computer can not use the wsock, the reason is not certified. I don't know why.
(2) BASP21.DLL Socket Object: This DLL can be used as an alternative to wsock controls. However, it is best not to use DLLs.
Http://www.hi-ho.ne.jp/babaq/eng/basp21s.html
(3) Csocketmaster 1.2 & Csocketplus 1.1
VB module, full code, non-control, the module into VBA can be. And there are detailed examples, in VB to run very well. But in VBA, cause Excel frequently crash, baffled, do not know why.
For example, there is a piece of code: CODE:[Copy to Clipboard] Const Mod_vba5 as String = "Vba5" ' Location of the Ebmode function if running VB5
Const Mod_vba6 as String = "Vba6" ' Location of the Ebmode function if running VB6
If Subclass_inide Then
' Patch the JMP (eb0e) with two NOP ' s (m) enabling the IDE breakpoint/stop checking code
Call Api_copymemory (ByVal Naddrsubclass +, &h9090, 2)

i = Subclass_addrfunc (Mod_vba6, FUNC_EBM) ' Get "the address of Ebmode in Vba6.dll
If i = 0 Then ' Found?
i = Subclass_addrfunc (Mod_vba5, FUNC_EBM) ' VB5 perhaps, try Vba5.dll
End If

Debug.Assert i ' ensure the Ebmode function was found
Call Subclass_patchrel (patch_01, i) ' PATCH the relative address to the Ebmode API function does not know this Ebmode Why, there's no value on MSDN. If you comment out this piece of code, will cause VB crash.

Http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=54681&lngWId=1
(4) CSocket class-replacement for the MS Winsock control
After a night, and finally found the module, the Csocketmaster mentioned above is also based on this adaptation.
Using this module on VBA, it is smoother.
Home: http://www.vbip.com/winsock-api/csocket-class/csocket-class-01.asp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.