[VB6 ] 請問一下各位高手大人 EXCEL存取陣列問題
小弟想用VB6來從活頁A裡儲存到B活頁裡
因為數量多,所以我不考慮用VBA
(別再跟我說VBA可用了...拜託^^")
我的方法是宣告一個陣列將活頁A裡內容存裡來
陣列裡的值再放進活頁B裡,請看我寫的程式碼:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Test.xls")
xlApp.DisplayAlerts = True
xlApp.Visible = True
xlBook.Activate
xlBook.Parent.Windows(1).Visible = True
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Activate
'以上宣告活頁A
Dim xlApp1 As Excel.Application
Dim xlBook1 As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Set xlApp1 = CreateObject("Excel.Application")
Set xlBook1 = xlApp1.Workbooks.Open(File1.Path & "\" & File1.FileName)
xlApp1.DisplayAlerts = True
xlApp1.Visible = True
xlBook1.Activate
xlBook1.Parent.Windows(1).Visible = True
Set xlSheet1 = xlBook1.Worksheets(1)
xlSheet1.Activate
'以上宣告活頁B
Dim data1(20) As Integer '行
Dim data2(20) As Integer '列
Dim i As Integer
Dim j As Integer
For i = 1 To 20
For j = 1 To 20
data1(i) = xlSheet.Cells(i, 1)
data2(j) = xlSheet.Cells(1, j)
xlSheet1.Cells(i, 1).Value = data1(i)
xlSheet1.Cells(1, j).Value = data2(j)
Next j
Next i
執行後..活頁B竟然什麼東西都沒有
請問可訢我那裡寫錯了嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.192.129
→
11/22 15:53, , 1F
11/22 15:53, 1F
抱歉..因為我不止要從一個活頁弄到A活頁裡
是非常非常..多的活頁..弄到A裡
※ 編輯: chrishappy11 來自: 123.195.192.129 (11/22 18:17)
→
11/22 21:53, , 2F
11/22 21:53, 2F
→
11/22 21:54, , 3F
11/22 21:54, 3F
→
11/22 23:24, , 4F
11/22 23:24, 4F
→
11/22 23:25, , 5F
11/22 23:25, 5F
→
11/22 23:27, , 6F
11/22 23:27, 6F
→
11/22 23:29, , 7F
11/22 23:29, 7F
→
11/22 23:34, , 8F
11/22 23:34, 8F