VB高手,请问以下语句为什么不能循环打开并输出修改后的txt文件?谢谢关注
例如我在excel表中有以下三行数据20120301 1
20120302 2
20120303 3
dim w as integer
w=1
dim wa wb as string
我将20120301设为c.cells(w,1).value ;"1"为c.cells(w,2).valaue
我的代码如下:
On Error Resume Next
Dim E As Object
Dim B As Object
Dim C As Object
Dim D As Object
Set E = CreateObject("excel.application")
E.Visible = True
Set B = E.Workbooks.Open("D:\T.xls")
Set C = B.worksheets(1)
C.Activate
Dim w as interger
w=1
dim wa ,wb as string
for w=1 to 3
wa=c.cells(w,1).value
wb=c.cells(w,2).valaue
Dim A As String
Dim s As String
Dim ss() As String
Open "D:\wa.txt" For Input As #1
Open "D:\GT\wb.txt" For Output As #2
Do Until EOF(1)
Line Input #1, s
‘省略
Loop
Close #1
Print #2, S1
Close #2
Next w --------------------编程问答-------------------- wb=c.cells(w,2).valaue
应为
wb=c.cells(w,2).value --------------------编程问答-------------------- 修改了:
Private Sub Form_Load()
On Error Resume Next
Dim E As Object
Dim B As Object
Dim C As Object
Dim D As Object
Dim s As String
Dim s1 As String
Set E = CreateObject("excel.application")
E.Visible = True
Set B = E.Workbooks.Open("D:\T.xls")
Set C = B.worksheets(1)
C.Activate
Dim w As Integer
w = 1
Dim wa, wb As String
For w = 1 To 3
wa = C.cells(w, 1).Value
wb = C.cells(w, 2).Value '
Debug.Print wa
Debug.Print wb
' wa和wb在此可修改,比如wb=5,只修改某行需计数
s = wa & " " & wb
s1 = s1 & s & vbCrLf
Next w
Open "D:\GT\wb.txt" For Output As #1
Print #1, s1
Close #1
End Sub
补充:VB , VBA