2 ohada19950721 ohada19950721 于 2016.01.27 20:03 提问

vb 把数据输入到excel表中

For m = 68 To 80 Step 3
For n = 12.6 To 16.2 Step 1.2
For o = 3.6 To 4.4 Step 0.2
For p = 210 To 275 Step 30
If m <> n And m <> o And m <> p And n <> o And n <> p Then
Print m; n; o; p
End If
Next
Next
Next
Next
怎么把print给换成是输入到excel表

2个回答

caozhy
caozhy   Ds   Rxr 2016.01.27 21:07
已采纳

两个办法,简单的,这么写:
open "x:\path\1.csv" for output as #1
For m = 68 To 80 Step 3
For n = 12.6 To 16.2 Step 1.2
For o = 3.6 To 4.4 Step 0.2
For p = 210 To 275 Step 30
If m <> n And m <> o And m <> p And n <> o And n <> p Then
Print #1 m &","& n & "," o & "," p
End If
Next
Next
Next
Next
close #1
虽然这个办法产生的不是真正的excel文件,但是csv文件也可以双击直接在excel打开。

另一个办法是引用Excel的COM组件,用VBA去操作。难度略大,你google下,能看懂,有问题可以问。看不懂我觉得你干脆放弃。我也懒得多说,

enpterexpress
enpterexpress   2016.01.27 20:13
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!