我试图打开一个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(zh-cn):“参数nicht可选。(Ausnahme von HRESULT:0x8002000F(DISP_E_PARAMNOTOPTIONAL))” 在Zeile:14 Zeichen:2 + $ App.Run(“ tata”) + ~~~~~~~~~~~~~~~~ + CategoryInfo:未指定:(:) [],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()
答案 0 :(得分:0)
调用宏时,您需要传递一个参数(目标):
$App.Run("tata", "value for target")