VBA Track file usage

后端 未结 2 886
礼貌的吻别
礼貌的吻别 2021-01-23 02:40

I currently have an excel file that produces client statements. I need to track who has run their statements. Currently, whenever statements are produced I have a macro that sen

2条回答
  •  萌比男神i
    2021-01-23 03:14

    I'd use a shared database, like SQL server or Access on a network share, rather than an e-mail. It's easier to work with than separate e-mails.

    If you must use e-mail, you can use a CDO object in your Excel macro, but your users must have access to an SMTP server on your network (usually an Exchange server works for this; look at your Outlook settings and see what server it's connected to). Generally this is not a problem if everyone has access to the same LAN resources.

    Add a reference in the VBA editor to Microsoft CDO for Windows 2000 Library (Tools->References in VBA. Don't worry about the "Windows 2000"; it should be available on your system).

    Example code

    Dim iMsg As CDO.Message
    Dim iConf As CDO.Configuration
    Dim Flds As ADODB.Fields
    
    Set iMsg = New CDO.Message
    Set iConf = New CDO.Configuration
    
    Set Flds = iConf.Fields
    
    With Flds
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        'Put the address of your SMTP server here
        .Item(cdoSMTPServer) = "smtp.example.com"
        .Item(cdoSMTPConnectionTimeout) = 10
        .Item(cdoSMTPAuthenticate) = cdoBasic
        .Item(cdoSendUserName) = "Username To Authenticate SMTP Server With"
        .Item(cdoSendPassword) = "Password To Authenticate SMTP Server With"
        .Item(cdoURLGetLatestVersion) = True
        .Update
    End With
    
    With iMsg
        Set .Configuration = iConf
        .From = "from@example.com"
        .ReplyTo = "replyto@example.com"
        .MimeFormatted = False
        .AutoGenerateTextBody = False
        .To = "to@example.com"
        .CC = "cc@example.com"
        .BCC = "bcc@example.com"
        .Subject = "Subject of Email"
        .HTMLBody = "HTML text to send"
    
        'If you need to add attachments
        .AddAttachment "C:\Local\Path\To\Attachment.xlsx"
    
        .Send
    End With
    

提交回复
热议问题