|
简单一点的代码- Sub UpdatingExcel(myPath As String)
- On Error Resume Next
- DoCmd.TransferSpreadsheet acImport, 8, "tblTempUpload", myPath, True, "Help!B3:j141"
- DoCmd.TransferSpreadsheet acImport, 8, "tblTempUpload", myPath, True, "Help!k3:s105"
- DoCmd.TransferSpreadsheet acImport, 8, "tblTempUpload", myPath, True, "Help!B142:j246"
- End Sub
复制代码 复杂一点的代码- Sub UploadCF(mth As String, myPath As String)
- Dim cnn, rst, sql$
- Set cnn = CreateObject("ADODB.Connection")
- Set rst = CreateObject("ADODB.Recordset")
- sql = "Select * From[Help$o3:w105] Where Balance<>0"
- DoCmd.SetWarnings False
- cnn.Open "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=Excel 8.0;Data Source=" & myPath
- Set rst = cnn.Execute(sql)
- While Not rst.EOF
- sql = "Update tblCFValues Set " & mth & "=" & rst("Balance") & " Where StoreNumber='" & _
- rst("StoreNumber") & "' And AccountSubject='" & rst("AccountSubject") & _
- "' And ReportKind='" & rst("ReportKind") & "' And FinYear=" & rst("FinYear") & _
- " And StoreBrand='" & rst("StoreBrand") & "' And BudgetOrFact='" & rst("BudgetOrFact") & "'"
- DoCmd.RunSQL sql
- rst.MoveNext
- Wend
- cnn.Close
-
- Set cnn = Nothing
- Set rst = Nothing
- DoCmd.SetWarnings True
- End Sub
复制代码 如果要多个Excel文档批量导入只需再引用FileSystemObject |
|