发送刷新的Excel表格每个工作日使用VBA Excel / Outlook

每天下午3点,我必须发一个Excel工作簿给同事。 工作簿中的macros只复制一个工作表中的所有单元格,并将select性粘贴到另一个工作表并保存该工作簿。 我已经写了macros来做到这一点,也发送到一个电子邮件地址,但我很难让它自动发送。 我已经指示了调度任务,但是我不知道如何在打开Excel,执行Marco,保存工作簿并将其发送给指定人员之间build立链接。 代码如下 – 感谢您的帮助。

Sub Fixing() Sheets("Sheet2").Select ActiveWindow.SmallScroll Down:=-9 Cells.Select Selection.Copy Sheets("Sheet1").Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _ xlNone, SkipBlanks:=False, Transpose:=False Range("I7").Select Application.CutCopyMode = False ActiveWorkbook.Save Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .to = "" .CC = "" .BCC = "my email address" .Subject = "Daily Email" .Body = "" .Attachments.Add ("F:\Excel Models\Daily Email.xlsm") .Send End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub 

创buildVBScript file例如使用下面的代码start excel action.vbs

  dim EXL set EXL = CreateObject("Excel.Application") 'not required EXL.Visible = true 'your file and macro EXL.Workbooks.Open "full path to your excel file including extension here" EXL.Run "Fixing" 'close everything EXL.Quit Set EXL = Nothing 

保存该文件并将Windows Task Scheduler设置为在下午3点运行该vbs文件。