Page 1 of 1

VBA Example on Excel 2003???

Posted: Sat May 29, 2010 3:55 pm
by MGeo
I've now got my SUB-20 up and running. I can communicate with it using subtool.exe and see sent messages on the LCD.

I would like for this to work from VBA running within Excel 2003. I followed the NET component instructions in sub20net.pdf to create the TLB file and get the correct responses:

C:\>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe /codebase /tlb "C:\Program Files\SUB-20\bin\sub20dnc.dll"
Microsoft (R) .NET Framework Assembly Registration Utility
2.0.50727.1433
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
Types registered successfully
Assembly exported to 'C:\Program Files\SUB-20\bin\sub20dnc.tlb', and the
type library was registered successfully
C:\>


I then add the tlb reference from Tools->References.

But when I run the sample book1.xls from the editor, I get an error in VBA:

Run-time error '-2147024894 (80070002)':
Automation error
The system cannot find the file specified.


I've tried unchecking the reference, closing and reloading the reference several times but to no avail.

Is this a common issue? Is there a way to fix this? I feel I'm close...

Best Regards,
George

Re: VBA Example on Excel 2003???

Posted: Sun May 30, 2010 4:05 am
by serg
Hi George,
Does it say what file is missing?
Try to unzip the attached file and put the excel.exe.config into the directory, where the EXCEL.EXE lives. On my machine it is in C:\Program Files\Microsoft Office\Office10. Run excell and try again.

Serg

Re: VBA Example on Excel 2003???

Posted: Sun May 30, 2010 10:35 am
by MGeo
That worked! I now have SUB20 working both in Excel 2003/VBA and Visual Studio 2008 / VB.NET.

I ran the following code in VBA and saw Hello World on my LCD...
  • Private Sub CommandButton1_Click()

    Dim Dev As New Sub20
    Dim ErrStr As String
    Dim Success As Boolean
    Dim Err As Integer

    Success = Dev.Open(0)
    If Not Success Then GoTo Done

    'write to the LCD
    If Not Dev.LCD_Write("\fHello\nWorld") Then
    GoTo Done
    End If

    Done:
    Err = Dev.GetLastError
    If Err > 0 Then
    ErrStr = Dev.GetStrError(Err)
    MsgBox ErrStr, vbCritical, "SUB-20 ERROR"
    End If
    Dev.Close

    End Sub
The Excel error I got did not tell me what was file or files were missing. Much fustration yesterday. I'm still climbing the learning curve on NET. I have 3.5 loaded on my WinXP laptop. I assume that was causing the trouble?

Anyway, thanks again for the help Serg.

George

Re: VBA Example on Excel 2003???

Posted: Mon May 31, 2010 12:24 am
by serg
No problem, George