access vba 操作excel

Private Sub showExcel()
  Dim xlApp As Excel.Application
  Set xlApp = CreateObject("Excel.Application")
  xlApp.Visible = True    '显示EXCEL应用程序
  '申明EXCEL工作簿对象
  Dim xlBook As Excel.Workbook
  '设置工作簿对象为指定的工作簿
  Set xlBook = xlApp.Workbooks.Open(CurrentProject.Path & "\导出结果\清册查询.xls")
  xlBook.Save
End Sub

 以上为显示excel表,以下为操作excel表

Private Sub myExcel()
'操作excel
Dim xlApp As Excel.Application
Set xlApp = GetObject(, "Excel.Application")
    '申明EXCEL工作簿对象
     Dim xlBook As Excel.Workbook
    '设置工作簿对象为指定的工作簿
     Set xlBook = xlApp.Workbooks.Open(CurrentProject.Path & "\导出结果\清册查询.xls")
     xlApp.Visible = False  '显示EXCEL应用程序
     hang = ActiveSheet.UsedRange.Rows.Count
     '以下部分为EXCEL录制宏录制整理后所得代码
    Range("A" & hang + 1).Select
    ActiveCell.FormulaR1C1 = "制表日期"
    Range("B" & hang + 1).Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Range("A" & hang + 2).Select
    ActiveCell.FormulaR1C1 = "总数"
    Range("B" & hang + 2).Select
    ActiveCell.FormulaR1C1 = hang - 1
    Range("A" & hang + 3).Select
    ActiveCell.FormulaR1C1 = "总额"
    Range("B" & hang + 3).Select
    ActiveCell.Formula = "=SUM(T6:T" & hang + 4 & ")"
    Range("A1:T" & hang).Select
    ActiveWindow.ScrollColumn = 14
    ActiveWindow.ScrollColumn = 13
    ActiveWindow.ScrollColumn = 12
    ActiveWindow.ScrollColumn = 11
    ActiveWindow.ScrollColumn = 9
    ActiveWindow.ScrollColumn = 8
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 1
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 1
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 1
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 1
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 1
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 1
        .TintAndShade = 0
        .Weight = xlThin
    End With
   Range("A" & hang + 1 & ":B" & hang + 5).Select
     '退应用程序并释放内存
     xlBook.Save
     xlBook.Close
     xlApp.Quit
     Set xlApp = Nothing
     Set xlBook = Nothing
End Sub

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值