Search code examples
excelvbasnmp

Excel VBA objsnmp.set strange things


I use the objSNMP.get method in Excel VBA without any problems.

I'd like to use the objSNMP.set method, but unfortunately it's not that easy. According to the website, it should work similarly to get, with the difference that there is one more parameter: the value to be sent.

If I try the official way:

objSNMP.Set ("43.18.1.1.2", OIDValue)

Image1 I get the message "Compile error: Syntax error". I found another solution that works conditionally. Namely as follows (it can be seen commented out in the picture):

randomVarName = objSNMP.Set("OID", Value)

For example:

temp = objSNMP.Set(".1.3.6.1.4.1.9.9.68.1.2.2.1.2." & PortNum, 21)

In this case, the code runs without error. This is interesting because I haven't found any official information about this anywhere. Somewhere deep in the recesses of the internet, I only found this possible solution some time ago.

If, on the other hand, I do not enter the value directly, but write the name of a variable there (e.g. VLANNum),

temp = objSNMP.Set(".1.3.6.1.4.1.9.9.68.1.2.2.1.2." & PortNum, VLANNum)

I receive an error message. Image2 It doesn't matter if the type of the variable is not declared, string or integer. I also tried several different cell types in Excel, but nothing changed.

The error message is:

Run-time error '-2147467259 (80004005)':

The requested SNMP operation attempted to modify a variable, but either a syntax or value error occurred.

Based on the above, I cannot insert the value read from the excel table at the end of the "objSNMP.Set" method in such a way that it can send the value. I could only solve the task if I create 4094 different "objSNMP.Set" lines and select what is necessary from among them. Not very efficient.


Solution

  • I have the solution. The value transferred with the variable works in the following form:

    objSNMP.Set ".1.3.6.1.2.1.2.2.1.7.9", CInt(x)
    

    Where x is the variable.