標題:
[發問]
VB.net 如何計算Excel中A欄位xlDown?
[打印本頁]
作者:
faye59
時間:
2018-6-22 05:38
標題:
VB.net 如何計算Excel中A欄位xlDown?
請問VB.net要如何算Excel內For迴圈的結束值?
我用VBA的方法都顯示xlDown跟xlUp都是無效
Wo Op Time
M123456789 OAG 01 10:00:00
M123456789 HAG 01 10:00:00
M123456789 SAG 01 10:00:00
M123456788 OAG 02 10:00:00
M123456788 SAG 02 10:00:00
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim WB, XL, oSheet As Object
XL = CreateObject("Excel.Application")
XL.Visible = False
WB = XL.Workbooks.Open("\\Test\test.xlsx", True)
oSheet = XL.Workbooks("Test.xlsx").Sheets("Text1")
'For i As Long = 1 To oSheet.Range("A100").End(xlUp).Row
'Dim aa As String = Wo.Text
'Dim bb As String = oSheet.Range("A2").End(xlUp)
'Dim rng As Range
rng = XL.range(XL.cells(1, 1), XL.cells(1, 1).End(xlDown))
For i As Integer = 1 To rng'要如何計算Excel內會迴圈總數?
oSheet.cells(4, i).value = "Test"
Next
XL.Workbooks("Test.xlsx").Save()
XL.DisplayAlerts = True
MsgBox("OK")
XL.Workbooks("Test.xlsx").Close()
XL.Application.Quit()
XL = Nothing
WB = Nothing
oSheet = Nothing
End Sub
複製代碼
作者:
faye59
時間:
2018-7-5 01:39
已找到解答了,分享給各位!
Constant Value
xlDown -4121
xlToLeft -4159
xlToRight -4161
xlUp -4162
Const xlUp = -4162
Const xlDown = -4121
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)