VBA Example on Excel 2003???

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
MGeo
Posts: 5
Joined: Thu May 27, 2010 10:20 am

VBA Example on Excel 2003???

Post 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

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: VBA Example on Excel 2003???

Post 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
Attachments
Excel.exe.config.zip
(351 Bytes) Downloaded 1196 times

MGeo
Posts: 5
Joined: Thu May 27, 2010 10:20 am

Re: VBA Example on Excel 2003???

Post 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

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: VBA Example on Excel 2003???

Post by serg »

No problem, George

Post Reply