I'm trying to open an excel sheet, run the macro and close it periodically to get an E-Mail notification when a date in a cell changes to "xxx".
Unfortuantely, powershell shows an error when running the macro below:
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))" In 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()
You need to pass an argument (Target) when calling the macro :
$App.Run("tata", "value for target")
User contributions licensed under CC BY-SA 3.0