.Open myDataEnd WithSQL = SELECT 入库.编号, 入库.物料凭证, 入库.车号, 入库.物料号, 入库.品种, 入库.牌号, _& 入库.规格, 入库.定尺, 入库.入库根数, 入库.牌重, 入库.吊号, 入库.炉批号, 入库.库房, _& 入库.销售状态, 入库.入库时间, 入库.盘盈, 入库.单价, [牌重]*[单价] AS 金额 _& FROM & myTable & WHERE 入库时间<=# & Sheet2.Range(E11) & # and 入库时间=# & Sheet2.Range(E10) & #Set rs = New ADODB.Recordsetrs.Open SQL, cnn, adOpenKeyset, adLockOptimisticFor i = 1 To rs.Fields.CountCells(1, i) = rs.Fields(i - 1).NameNext iWith Range(Cells(1, 1), Cells(1, rs.Fields.Count)).Font.Bold = True.HorizontalAlignment = xlCenterEnd WithRange(A2).CopyFromRecordset rsActiveSheet.Cells.Font.Size = 10ActiveSheet.Columns.AutoFitrs.Closecnn.CloseSet rs = NothingSet cnn = NothingApplication.ScreenUpdating = TrueEnd Sub上面的这个过程里,包括了使用ADODB打开Access库,用SQL提取记录集,然后写入Excel单元格的完整示例,希望对你有所启发
温馨提示:答案为网友推荐,仅供参考