06-22-2017 07:01 AM
Hi,
I wonder if it is possible to use the object library of Diadem, which is normally available in the DIADEM Scripting module, also in Excel-VBA? Are there DLL-Files or something like that, which have to be referenced to the VBA-Project, to have access to the DIADEM object library? If so, what are their names? If not, is there an alternative to achieve this possibility?
It would be great if somebody has an idea!
Greetings Joerg
06-22-2017 07:18 AM - edited 06-22-2017 07:23 AM
Hi Joerg,
You can find a good example here:
http://zone.ni.com/reference/en-XX/help/370858M-01/exploff/examples/example_ole/
Copy and paste the example code to an Excel VBA macro and execute it after some simple changes.
The only thing you have to do is uncomment the procedure calls you need and maybe put them into another procedure that will be called by excel:
Sub runDemo() Call ConnectToDIAdem Call LoadDiademDataSet Call LoadDiademLayout Call DisconnectFromDIAdem End Sub
You don't need any additional DLLs. If DIAdem is installed, the automation interface (COM object) should be also registered.
The function DIAdem_exec(DIAdemCommand) is used in this demo to execute DIAdem script commands.
Find an overview of methods and properties of the DIAdem TOCommand automation object here:
http://zone.ni.com/reference/de-XX/help/370858M-0113/ole/objects/ole_objects_itocommand/
Regards
06-22-2017 08:38 AM
Hallo Christian,
Thanks for the quick replay. But actually your solution I knew already and this is not what I meant. I hoped one can directly link a VBA-project, for instance in Excel, with the same object library one normally use in the scripting module of Diadem with VBS. For this one has to reference some COM-Library or something like that in the VBA-Editor. See the attached picture. In this case one can use more or less the same object structure in the VBA-Code like in the VBS-Script of Diadem.
I need this for instance to dynamically link via VBA some selective data of a certain channel in DIADEM with some data in a table of an Excel spreadsheet. To make this possible until now, I had to transfer all my channel data in DIADEM to an additional Excel-File. So that I can use this Excel-file as an additional data source to link it with my final Excel-Table. But in this case I have redundant source data. If I change something in DIADEM, which I normally us to manage my measured data, I have to create my additional Excel-source data again and so on.
This was just a little example for what such direct VBA-access to diadem would be useful. For we use to work with DIADEM and Excel quite often together, such a direct VBA-access would make our work more efficiently.
Greetings Joerg
06-22-2017 02:29 PM
Hi Joerg,
Your only option to use DIAdem VBScript functions from a language outside DIAdem is to connect to an installed DIAdem application via ActiveX. There is no external library you can connect to without talking through the DIAdem application.
Sorry,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
03-13-2019 12:24 PM
I have begun to play around with this example and when I try to execute the function "ConnectToDIAdem()"
The script creates an error when trying to create the DIAdem.TOCommand object
The error i get is
below is my procedure
Option Explicit Dim oDIAdem Const strCanNotStart = "An error has occurred while executing the example." Sub runDemo() Call ConnectToDIAdem 'Call LoadDiademDataSet 'Call LoadDiademLayout Call DisconnectFromDIAdem End Sub Function ConnectToDIAdem() Dim nValueT, iWait ConnectToDIAdem = 0 On Error Resume Next oDIAdem = CreateObject("DIAdem.TOCommand") If Err.Number > 0 Then MsgBox ("Err No " & CStr(Err.Number) & " " & Err.Description) Err.Clear Else iWait = 0 Do iWait = iWait + 1 If iWait >= 1000 Then If MsgBox("DIAdem is not responding. Try again?", vbYesNo, "Warning") = vbYes Then iWait = 0 Else Exit Function End If End If Loop Until Not oDIAdem.bInterfaceLocked ' Suppress all messages oDIAdem.bNoMsgDisplay = True oDIAdem.bNoInfoDisplay = True oDIAdem.bNoErrorDisplay = True oDIAdem.bNoWarningDisplay = True oDIAdem.bNoNoDialogDisplay = True ConnectToDIAdem = 1 End If End Function Sub LoadDiademDataSet() MyCommand = "DataFileImport(ProgramDrv + 'examples\data\report_expl.tdm')" If DIAdem_exec("DataDelAll(1)") <> 1 Then Call DIAdem_exec(MyCommand) End If End Sub Sub DisconnectFromDIAdem() Set oDIAdem = Nothing End Sub
03-15-2019 04:49 PM
Hi Tim,
The CreateObject() command always returns an object variable, and object variable assignments in VBScript require the "Set " prefix:
Set ToCommand = CreateObject("DIAdem.ToCommand")
I also recommend that you only put one command line between "On Error Resume Next" and "On Error Goto 0". It's just too hard to debug when you're suppressing any syntax errors you've typed.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
03-18-2019 04:38 AM
Thanks Brad
I copied the script from the knowledge articles and made the assumption they were correct
http://zone.ni.com/reference/en-XX/help/370858M-01/exploff/examples/example_ole/