Use Excel to retrieve and list Available com ports in a combobox

ArnMan

Board Regular
Joined
Aug 30, 2017
Messages
69
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I have been using Excel VBA to access a com port and do some functions with. Usually I have to find out what my port is and type the number in a cell, and my code takes it from there.
Is there a way to have a combobox that when it is dropped down, to list the available com ports for me to choose? Then I could select the com port I am using and let my code run with that. That way I wouldn't have to go into device manager to see what I have already.
Any help or direction would be greatly appreciated.

Thank you in advance
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Here is a short sub I have that access my com port that I type in, so you can see what I am using to actually use the port with.

VBA Code:
Private Sub CalVolts_Click()


    Dim nameArray As Variant, full As String, reading As String, command As String, mode As String, unitrange As String
    Dim fluke798 As Range
    
    Dim ioMgr As VisaComLib.ResourceManager
    Dim instrument As VisaComLib.FormattedIO488
    Dim sndBuffer As String
    Dim rcvBuffer As String
    Dim myCommStr As String
    Dim myStatus As Integer
    
   Set addstdvalue = Range("H2")
    Set ioMgr = New VisaComLib.ResourceManager
    Set instrument = New VisaComLib.FormattedIO488
    'myCommStr = "ASRL1::INSTR"
    'Set instrument.IO = ioMgr.Open(myCommStr)
    Set instrument.IO = ioMgr.Open("ASRL" & addstdvalue.Value & "::INSTR")
    
    ' Set serial interface-specific attributes...
    Dim serInfc As VisaComLib.ISerial
    Set serInfc = instrument.IO
    serInfc.BaudRate = 9600
    serInfc.FlowControl = ASRL_FLOW_NONE
    serInfc.Timeout = 10000
    instrument.IO.SendEndEnabled = True
    instrument.IO.TerminationCharacter = 10          ' could be 10 (line feed) or 13 (carriage return)
    instrument.IO.TerminationCharacterEnabled = True
    instrument.IO.Timeout = 10000
    
    'rcvBuffer = commQuery(instrument, "QM")       ' query the ID and place on the worksheet to let the user know it was found
    'rcvBuffer = Replace(rcvBuffer, vbLf, "")          ' strip off the carriage return
    'ActiveSheet.Cells(6, 10) = rcvBuffer
    
    instrument.WriteString "HC_GASUI_OFF;display upper,off;display middle, off;display lower, on;func lower,dcv"
    




End Sub
 
Upvote 0

Forum statistics

Threads
1,216,731
Messages
6,132,393
Members
449,725
Latest member
Enero1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top