0
這個子程序運作良好,但現在我得到一個「循環離不開」錯誤:「你不循環」錯誤
Sub Upload_earned_pto()
Dim conn As New ADODB.Connection
Dim iRowNo As Integer
Dim UID, PW, s1, s3, s5, s7 As String
Dim s4, s6 As Date
Dim s2 As Double
UID = ThisWorkbook.Sheets("Sheet1").Range("A1")
PW = ThisWorkbook.Sheets("Sheet1").Range("B1")
With Sheets("Monthly Adjustments")
'Open a connection to SQL Server
conn.Open "Provider=SQLOLEDB.1;Password=" & PW & ";Persist Security Info=True;User ID=" & UID & ";Initial Catalog=TESTDB;Data Source=TESTSRV;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=MPL-DEV1;Use Encryption for Data=False;Tag with column collation when possible=False"
'Skip the header row
iRowNo = 8
'Loop until empty cell in batch_skey
Do Until .Cells(iRowNo, 1) = ""
If Rows(iRowNo).Hidden = True Then
iRowNo = iRowNo + 1
ElseIf Rows(iRowNo).Hidden <> True Then
s1 = .Cells(iRowNo, 1)
s2 = .Cells(iRowNo, 2)
s3 = .Cells(iRowNo, 3)
s4 = .Cells(iRowNo, 4)
s5 = .Cells(iRowNo, 5)
s6 = .Cells(iRowNo, 6)
s7 = .Cells(iRowNo, 7)
'Generate and execute sql statement to export the excel rows to SQL Server table
conn.Execute "insert into dbo.pto_transactions values ('" & s1 & "', '" & s3 & "'
, '" & s6 & "', '" & s2 & "', '" & s4 & "', '" & s5 & "', '" & s7 & "')"
iRowNo = iRowNo + 1
Loop
MsgBox "PTO Transactions Successfully Sent."
conn.Close
Set conn = Nothing
End With
你錯過了一個'end if' –
我是白癡!錯過了我的結局如果! –
@ScottCraner謝謝你!從字面上看,只是注意到它,併發布我的評論。 –