Excel 对象 作为对象的Dim-iConf 作为变型的Dim FLD 设置iMsg=CreateObject(“CDO.Message”) 设置iConf=CreateObject(“CDO.Configuration”) iConf.Load-1 设置Flds=

Excel 对象 作为对象的Dim-iConf 作为变型的Dim FLD 设置iMsg=CreateObject(“CDO.Message”) 设置iConf=CreateObject(“CDO.Configuration”) iConf.Load-1 设置Flds=,excel,outlook-2007,vba,Excel,Outlook 2007,Vba,对象 作为对象的Dim-iConf 作为变型的Dim FLD 设置iMsg=CreateObject(“CDO.Message”) 设置iConf=CreateObject(“CDO.Configuration”) iConf.Load-1 设置Flds=iConf.Fields 使用FLD .项目(”http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .项目(”http://schemas.microsoft.com/c

对象 作为对象的Dim-iConf 作为变型的Dim FLD 设置iMsg=CreateObject(“CDO.Message”) 设置iConf=CreateObject(“CDO.Configuration”) iConf.Load-1 设置Flds=iConf.Fields 使用FLD .项目(”http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .项目(”http://schemas.microsoft.com/cdo/configuration/smtpserver“”=“测试-svr-002” .项目(”http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .更新 以 与iMsg Set.Configuration=iConf .To=”test@gmail.com" .From=”test@gmail.com" .Subject=“MIS报告”和“&”日期和时间 .TextBody=“链接到Mis报告:”&vbNewLine&“ .发送 以 设置iMsg=无 设置iConf=Nothing 端接头 函数getFileLink()作为字符串 Dim fso作为对象,MyFolder作为字符串 设置fso=CreateObject(“Scripting.FileSystemObject”) MyFolder=ThisWorkbook.Path&“\Reports” 如果fso.FolderExists(MyFolder)=False,则 fso.CreateFolder(MyFolder) 如果结束 MyFolder=MyFolder&“\”格式(现在为(),“MMM\U YYYY”) 如果fso.FolderExists(MyFolder)=False,则 fso.CreateFolder(MyFolder) 如果结束 getFileLink=MyFolder&“\MIS”和Format(Now(),“DD-MM-YY hh.MM.ss”)和“.xls” 设置fso=无 端函数
这非常有效!非常感谢。我该如何打开它,每天下午4:30刷新?@user184581在单元格A3、A4中输入时间……以此类推,您可以延长时间。要运行此宏,PC必须是独立的。我在办公室里使用的是同一个宏,它正在成功运行。用户所做的是在早上打开此工作簿,并在指定的时间范围内运行。我将向您推荐这种方法。我找到了另一种方法,它非常有效,只是我不能在我的远程环境中使用MS任务调度器。在这里,我必须打开嵌入access查询的excel文件。我喜欢上面的代码,但我不想通过链接发送数据……我更喜欢下面方法中的html而不是电子邮件正文。但是,如果没有计划程序,我如何实现自动化?此工作簿的私有子工作簿\u Open()运行“邮件\u工作表\u Outlook\u正文”结束子模块1函数RangetoHTML(rng As Range)在Excel 2000、Excel 2002、Excel 2003、Excel 2007、Excel 2010、Outlook 2000、Outlook 2002、Outlook 2003、Outlook 2007和Outlook 2010中工作。Dim fso As Object Dim ts As Object Dim TempFile As String Dim TempWB As WORK TempFile=ENVIRO$(“temp”)&“/”格式(现在是“dd mm yy h-mm-ss”)&“.htm”复制范围并创建工作簿以接收数据。rng.Copy Set TempWB=Workbooks.Add(1)和TempWB.Sheets(1)End函数保留了其余的代码,因为它太长了。这太棒了!非常感谢。我该如何打开它,每天下午4:30刷新?@user184581在单元格A3、A4中输入时间……以此类推,您可以延长时间。要运行此宏,PC必须是独立的。我在办公室里使用的是同一个宏,它正在成功运行。用户所做的是在早上打开此工作簿,并在指定的时间范围内运行。我将向您推荐这种方法。我找到了另一种方法,它非常有效,只是我不能在我的远程环境中使用MS任务调度器。在这里,我必须打开嵌入access查询的excel文件。我喜欢上面的代码,但我不想通过链接发送数据……我更喜欢下面方法中的html而不是电子邮件正文。但是,如果没有计划程序,我如何实现自动化?此工作簿的私有子工作簿\u Open()运行“邮件\u工作表\u Outlook\u正文”结束子模块1函数RangetoHTML(rng As Range)在Excel 2000、Excel 2002、Excel 2003、Excel 2007、Excel 2010、Outlook 2000、Outlook 2002、Outlook 2003、Outlook 2007和Outlook 2010中工作。Dim fso As Object Dim ts As Object Dim TempFile As String Dim TempWB As WORK TempFile=ENVIRO$(“temp”)&“/”格式(现在是“dd mm yy h-mm-ss”)&“.htm”复制范围并创建工作簿以接收数据。rng.Copy Set TempWB=Workbooks.Add(1)和TempWB.Sheets(1)End函数保留了代码的其余部分,因为它太长了
Sub Mail_Workbook()
Dim OutApp As Object
Dim OutMail As Object
Dim EmailAddr As String
Dim Subj As String



Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = "me.meeee@company.com"
.CC = ""
.BCC = ""
.Subject = "***TEST*** " & Subj
.Body = Subj
.Attachments.Add ActiveWorkbook.FullName
.Display
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%S"
End With
Set OutMail = Nothing
End Sub
 Private Sub Workbook_Open()
    RunMacro
End Sub
Sub RunMacro()


    Dim a As String, b As String, c As String, d As String, e As String

    a = Format(Range("A3"), "hh:mm:ss")
    b = Format(Range("A4"), "hh:mm:ss")
    c = Format(Range("A5"), "hh:mm:ss")
    d = Format(Range("A6"), "hh:mm:ss")
    e = Format(Range("A7"), "hh:mm:ss")


    Application.OnTime TimeValue(a), "MIS"
    Application.OnTime TimeValue(b), "MIS"
    Application.OnTime TimeValue(c), "MIS"
    Application.OnTime TimeValue(d), "MIS"
    Application.OnTime TimeValue(e), "MIS"
End Sub

Sub MIS()

'open the workbook
    Dim wkb As Workbook
    Dim Path As String, strFile As String, strFilePath As String

    strFile = "file1.xlsx"
    Path = ThisWorkbook.Path & "\" & strFile

    If IsWorkBookOpen(Path) Then
        Set wkb = Workbooks(strFile)
    Else
        Set wkb = Workbooks.Open(Path)
    End If

    'Refresh the data
    wkb.RefreshAll

    'get new filePath
    strFilePath = getFileLink

    wkb.SaveAs Filename:=strFilePath 
    wkb.Close

    'send mail
    SendMail strFilePath


End Sub

Function IsWorkBookOpen(FileName As String)
'Check if workbooks is open
'IsOpen Return true

    Dim ff As Long, ErrNo As Long

    On Error Resume Next
    ff = FreeFile()
    Open FileName For Input Lock Read As #ff
    Close ff
    ErrNo = Err
    On Error GoTo 0

    Select Case ErrNo
    Case 0: IsWorkBookOpen = False
    Case 70: IsWorkBookOpen = True
    Case Else: Error ErrNo
    End Select
End Function

Sub SendMail(myDest As String)
'procedure to send mail
'you need to configure the server & port

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant


    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1
    Set Flds = iConf.Fields

    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "test-svr-002"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With

    With iMsg

        Set .Configuration = iConf
        .To = "test@gmail.com"
        .From = "test@gmail.com"
        .Subject = "MIS Reports" & " " & Date & " " & Time
        .TextBody = "Link to Mis Report :" & vbNewLine & "<" & myDest & ">"
        .Send
    End With

    Set iMsg = Nothing
    Set iConf = Nothing

End Sub

Function getFileLink() As String

    Dim fso As Object, MyFolder As String
    Set fso = CreateObject("Scripting.FileSystemObject")

    MyFolder = ThisWorkbook.Path & "\Reports"


    If fso.FolderExists(MyFolder) = False Then
        fso.CreateFolder (MyFolder)
    End If

    MyFolder = MyFolder & "\" & Format(Now(), "MMM_YYYY")

    If fso.FolderExists(MyFolder) = False Then
        fso.CreateFolder (MyFolder)
    End If

    getFileLink = MyFolder & "\MIS " & Format(Now(), "DD-MM-YY hh.mm.ss") & ".xls"
    Set fso = Nothing

End Function