Arduino serial connection to Excel VBA, no third party software needed

... hope it helps!

--- Arduino code ---------------------------------------------------------------------

byte ledStates = 0;

void setup() {
  Serial.begin(115200);
}

void loop() {
  if(Serial.available()){serialComm();}    
}

void serialComm(){
  switch(Serial.read())
    case 65: {  // ascii for "A" received from Excel VBA
      Serial.readBytes(ledStates, 8 );   // receiving from Excel VBA
      Serial.print("This goes to Excel");   // sending to Excel VBA
   break;  
  }  
}

--- VBA code --------------------------------------------------------------------------

Dim COM2file As Integer

Public Sub ArdCOM2()
    
    COM2file = FreeFile
    Open "COM2:115200,BIN,CD0,CS0,DS0,OP0,RB64,RS,TB64" For Binary Access Read Write As #COM2file
    
    Put #COM2file, , "A" 'send 1 byte to Arduino
    Put #COM2file, , "01001100" 'send 8 bytes to Arduino, could be led states
    
    ArdIn = Input(1, #COM2file) 'receive 1 byte from Arduino
    ArdIn = Input(5, #COM2file) 'receive 5 bytes from Arduino

     Close #COM2file
    
 End Sub

hi,

I'm interrested in this solution, but :

what does this mean : COM2file = FreeFile

and how do you get it to work ?

thanks

flyjodel:
hi,

I'm interrested in this solution, but :

what does this mean : COM2file = FreeFile

and how do you get it to work ?

thanks

If you have VBA, http://www.pencomdesign.com/support/relay_software/vba_software_example.htm

dgar:
... hope it helps!

What Arduino are you using?

I suspect that code would not work with an Uno or Mega which are reset when the PC program opens the serial port.

...R

Robin2:
What Arduino are you using?

I suspect that code would not work with an Uno or Mega which are reset when the PC program opens the serial port.

...R

The OP hasn't been on the message board since 2014.

ieee488:
The OP hasn't been on the message board since 2014.

Doh!

...R