VBA 串口通信教程 Excel

wxxloveu 2010-01-24 10:23:59
最好是视频教程,哪里有地址啊?
我现在要实现从RS232传一些数据直接到Excel中
本人原来是做C#的,了解一点VBA的知识,没用他实际编程过,还望各路英豪不吝分享资源啊……
...全文
3330 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxxloveu 2010-01-27
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 chinaboyzyq 的回复:]
呵呵,好的,谢谢啊。
可能是mscomm32.ocx控件有问题,或者是没有注册好。
[/Quote]
弱弱的问下:我的Excel不是正版的……会有影响不?
wxxloveu 2010-01-27
  • 打赏
  • 举报
回复

[Quote=引用 11 楼 qiangshou2301 的回复:]
怎么样了 找到了吗
[/Quote]
去这里看吧
http://topic.csdn.net/u/20100126/13/e769a2bf-0920-472d-9502-003814a7cdad.html
chinaboyzyq 2010-01-27
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 wxxloveu 的回复:]
引用 18 楼 chinaboyzyq 的回复:
呵呵,好的,谢谢啊。
可能是mscomm32.ocx控件有问题,或者是没有注册好。

弱弱的问下:我的Excel不是正版的……会有影响不?
[/Quote]
不会

mscomm32.ocx应该是VB6的控件与excle无关。
chinaboyzyq 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 wxxloveu 的回复:]
引用 13 楼 chinaboyzyq 的回复:
在msdn中看mscomm控件的用法。
在vba内引用mscomm控件。
在vba帮助中看vba如何把取来的数写到单元格里面以及怎么保存。


呵呵,好的,谢谢啊。
为什么我在添加MSComm控件时,系统显示“对指定的操作,该主题不受信任。”?
(在Excel中用VBA)
[/Quote]

可能是mscomm32.ocx控件有问题,或者是没有注册好。
开发测试时你可先在你的系统上先安装VB6并打sp6补丁,再试试添加部件。
(我的台式机和本子上均有vb6,所以没测试不安装VB6时的情况,你以后有空时再自己测试吧,可考虑用打包安装程序去安装注册mscomm.ocx这个控件)
wxxloveu 2010-01-26
  • 打赏
  • 举报
回复
在注册表中可以找到 HKEY_CLASSES_ROOT\Licenses,有4250E830-6AC2-11cf-8ADB-00AA00C00905项 内容为:kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun
这样应该是注册好了的吧,怎么还是不行呀
wxxloveu 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 qiangshou2301 的回复:]
找到这样的资源没有
[/Quote]
没有,有再和你说吧
wxxloveu 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 chinaboyzyq 的回复:]
在msdn中看mscomm控件的用法。
在vba内引用mscomm控件。
在vba帮助中看vba如何把取来的数写到单元格里面以及怎么保存。

[/Quote]
呵呵,好的,谢谢啊。
为什么我在添加MSComm控件时,系统显示“对指定的操作,该主题不受信任。”?
(在Excel中用VBA)
qiangshou2301 2010-01-26
  • 打赏
  • 举报
回复
找到这样的资源没有
chinaboyzyq 2010-01-26
  • 打赏
  • 举报
回复
在msdn中看mscomm控件的用法。
在vba内引用mscomm控件。
在vba帮助中看vba如何把取来的数写到单元格里面以及怎么保存。
wxxloveu 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 qiangshou2301 的回复:]
怎么样了 找到了吗
[/Quote]
找到什么呀?
ACMAIN_CHM 2010-01-25
  • 打赏
  • 举报
回复
直接在VBA中引用这个MSComm 控件
wxxloveu 2010-01-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 acmain_chm 的回复:]
和VB关系不大,你主要是需要了解一下com控件的使用方法。这个在MSDN中有例子。
[/Quote]
听老板说在Excel里可以直接用VBA来实现串口通信?这样要怎么做啊
wxxloveu 2010-01-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lb_bn 的回复:]
学习了。谢谢楼上。
[/Quote]
你也在做串口编程?一起学习啊
qiangshou2301 2010-01-25
  • 打赏
  • 举报
回复
怎么样了 找到了吗
wxxloveu 2010-01-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 acmain_chm 的回复:]
直接在VBA中引用这个MSComm 控件
[/Quote]
谢谢了,终于明白RS232通信了,我用c#的serialport控件可以接受传送的数据……
找个时间试试VBA……
qiangshou2301 2010-01-25
  • 打赏
  • 举报
回复
帮顶
lb_bn 2010-01-24
  • 打赏
  • 举报
回复
学习了。谢谢楼上。
ACMAIN_CHM 2010-01-24
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/aa259393(VS.60).aspx
MSComm Control


MSComm Control Example
The following simple example shows basic serial communications using a modem:

Private Sub Form_Load ()
' Buffer to hold input string
Dim Instring As String
' Use COM1.
MSComm1.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input
' is used.
MSComm1.InputLen = 0
' Open the port.
MSComm1.PortOpen = True
' Send the attention command to the modem.
MSComm1.Output = "ATV1Q0" & Chr$(13) ' Ensure that
' the modem responds with "OK".
' Wait for data to come back to the serial port.
Do
DoEvents
Buffer$ = Buffer$ & MSComm1.Input
Loop Until InStr(Buffer$, "OK" & vbCRLF)
' Read the "OK" response data in the serial port.
' Close the serial port.
MSComm1.PortOpen = False
End Sub
Note The MSComm control can use polling or an event-driven method to retrieve data from the port. This simple example uses the polling method. For an example of the event-driven method, see help for the OnComm event.

ACMAIN_CHM 2010-01-24
  • 打赏
  • 举报
回复
和VB关系不大,你主要是需要了解一下com控件的使用方法。这个在MSDN中有例子。
laoyebin 2010-01-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 acmain_chm 的回复:]
http://msdn.microsoft.com/en-us/library/aa259393(VS.60).aspx
MSComm Control


MSComm Control Example
The following simple example shows basic serial communications using a modem:

Private Sub Form_Load ()
  ' Buffer to hold input string
  Dim Instring As String
  ' Use COM1.
  MSComm1.CommPort = 1
  ' 9600 baud, no parity, 8 data, and 1 stop bit.
  MSComm1.Settings = "9600,N,8,1"
  ' Tell the control to read entire buffer when Input
  ' is used.
  MSComm1.InputLen = 0
  ' Open the port.
  MSComm1.PortOpen = True
  ' Send the attention command to the modem.
  MSComm1.Output = "ATV1Q0" & Chr$(13) ' Ensure that
  ' the modem responds with "OK".
  ' Wait for data to come back to the serial port.
  Do
      DoEvents
  Buffer$ = Buffer$ & MSComm1.Input
  Loop Until InStr(Buffer$, "OK" & vbCRLF)
  ' Read the "OK" response data in the serial port.
  ' Close the serial port.
  MSComm1.PortOpen = False
End Sub
Note  The MSComm control can use polling or an event-driven method to retrieve data from the port. This simple example uses the polling method. For an example of the event-driven method, see help for the OnComm event.


[/Quote]

嗯,不错的DD
加载更多回复(1)

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧