【发布时间】:2019-03-08 13:47:48
【问题描述】:
我正在尝试打开一个 Excel 工作表,运行宏并定期关闭它,以便在单元格中的日期更改为“xxx”时收到电子邮件通知。
不幸的是,powershell 在运行下面的宏时显示错误:
Sub tata(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count < 1 Then Exit Sub
Set xRg = Intersect (Range("AT28:AT673"), Target
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value = 1 Then
Call Mail_small_Text_outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody as String
Set xOutApp = Create.Object("Outlook.Application")
Set xOutMail = xOut.App.CreateItem(0)
xMailBody = "Hi" & vbNewLine & _
""
On error Resume Next
With xOutMail
.To = "Name@domainname.com"
.CC = ""
.BCC = ""
.Subject = "order"
.Body = "xMailbody
.Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Ausnahme beim Aufrufen von "Run" mit 1 Argument(en): "Parameter nicht optional. (Ausnahme von HRESULT: 0x8002000F (DISP_E_PARAMNOTOPTIONAL))" 在 Zeile:14 Zeichen:2 + $App.Run("tata") + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : COMException
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbookMacroEnabled
$app = New-Object -comobject Excel.Application
$app.Visible = $True
$app.DisplayAlerts = $False
$wb = $App.Workbooks.Open("c:\my.xlsm")
$App.Run("tata")
$app.ActiveWorkbook.Saves
$app.Quit()
【问题讨论】:
标签: excel vba powershell