`
deepfuture
  • 浏览: 4337948 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79477
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68493
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101635
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281480
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14633
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65702
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31370
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45290
社区版块
存档分类
最新评论

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

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics