.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
今天的收获---实现excel工资单的自动发送

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

每个公司每月发工资的同时要给每个员工一张工资单。而发工资单的主要目的是让员工知道自己一个月来工资组成的详细情况,确认财务结算是否有误。一般的处理方式是直接在原来全员工资表的基础上给每个员工记录前插入表头等整张打印出来后一条一条的剪裁出来发给各个员工。这种方式对小公司来说还可以,但当公司达到好几十上百或上千的员工时,财务人员光每个月剪裁着工资单就要花不少时间,而且还要花费很多纸张

我们的解决方式是将每个人的表头及工资记录提取出来重新生成一个xls文件,同时启动outlook将它作为附件发送给相应的个人。这样每个月公司的财务人员做好了全员工资报表后只要点击一下一个按钮就可完成。这样既节省了财务人员的时间降低了他们的工作强度使他们有更多精力去做专业的事,同时也为公司节约了纸张。----别看小小纸张,在好多公司打印纸的消耗量有多大大家心里应该都有数,这可是一笔不小的开销啊。

该文就以上面的思想为主线来实现。具体代码如下:

Private Sub CommandButton1_Click()
    Dim outFile
    Dim Email
    Dim cn As New ADODB.Connection
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Dim oOutlookApp As New Outlook.Application
    Dim oItemMail As Outlook.MailItem
    Set oItemMail = oOutlookApp.CreateItem(olMailItem)
   
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=C:\Documents and Settings\gw\My Documents\Book3.xls;" & _
               "Extended Properties=""Excel 8.0;"""
    cn.Open
   
    Set xlApp = New Excel.Application
   
   
    MsgBox "Creat ready." & [a1].End(xlDown).Row, vbInformation
   
    For i = 2 To [a1].End(xlDown).Row
       
        Email = Cells(i, 11)
        MsgBox "Creat ready." & Email, vbInformation
        Set xlBook = xlApp.Workbooks.Add
        Set xlSheet = xlBook.ActiveSheet
   
        MsgBox "Creat is beginning." & i, vbInformation
   
        xlSheet.Range("a1:k1").Value = Range("a1:k1").Value
        xlSheet.Range("a2:k2").Value = Range("a" & i & ":k" & i).Value
       
  
       
        outFile = "C:\Documents and Settings\" & Cells(i, 4) & ".xls"
       
        MsgBox "Creat file name." & outFile, vbInformation
       
        xlBook.SaveAs "C:\Documents and Settings\" & Cells(i, 4) & ".xls"
       
        MsgBox "Creat file " & outFile & "is closing", vbInformation
       
        xlBook.Close False
       
        MsgBox "Creat file " & outFile & "close", vbInformation
       
        With oItemMail
            .Subject = "工资单"
            .Body = "请确认你的工资单,若有问题在本月10号之前到财务处确认"
            .Attachments.Add (outFile)
            .Importance = olImportanceHigh
            .Recipients.Add (Email)
            .Sensitivity = olPersonal
            .Send
        End With
       
        outFile = ""
        Email = ""
        Set oItemMail = oOutlookApp.CreateItem(olMailItem)
       
        MsgBox "Mail" & (i - 1) & " is Created"
   
    Next    
    
    cn.Close
    Set cn = Nothing
   
    MsgBox "all finish", vbInformation
End Sub

各位只要在工资表上加一个BUTTON,再把这段代码略加修改就可使用了

 




相关文章

相关软件