Outlook WordEditor failure

Started by stanl, April 15, 2021, 01:20:57 PM

Previous topic - Next topic

stanl

I'm developing a script at work automating downloading SFTP files, converting to Excel, copying a range to clipboard, saving Excel file then generating an outlook email with HTML text, the range copied to the email body and the file attached. A lot of this is done in Powershell but I would like to sneak in a wb exe to handle the outlook portion:  and I hit a wall. The script below just brings up the email. I included the HTML body and you can fill in a fake recipient, pick a file to attach and put something in the clipboard.... the script fails on


email.GetInspector.WordEditor.Range(0,0).Paste()


yet the Powershell version: $email.GetInspector.WordEditor.Range(0,0).Paste() works as both scripts are identical except for the $ preceding the PS variables/objects.  Hope someone can point out an easy fix.
Code (WINBATCH) Select


;assume an Excel Range has been loaded to clipboard
;to run the script with error, copy something there
;preferably an excel range
cTo = "stan@winbatch.com"   ;use your own
cSub = "Automating sending Outlook Message with attachment "
data = "<test.xlsx>" ;add your own path/file
cBody = fileget("C:\temp\test.txt") ;simple text with HTML wrappers
outlook = CreateObject("Outlook.Application")
email = outlook.CreateItem(0)
email.GetInspector.Activate()
sSig = email.HTMLBody
email.To = cTo
email.HTMLBody =  cBody:sSig
email.GetInspector.WordEditor.Range(0,0).Paste() ;comment to avoid error
email.Attachments.add(data)


;email.Send()
ObjectClose(outlook)
outlook = 0

td

All I can say is that it works for me...
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Quote from: td on April 15, 2021, 02:19:00 PM
All I can say is that it works for me...


Thanks. It works in VBA, which was the source for both scripts. Probably an issue with my Outlook [Office 2019].

stanl

I found the problem. I made a post a ways back about how to have both 32 and 64 bit Ace Providers. Seems the Access Database Engine 2016 I installed to accomplish that made the WordEditor fail. I uninstalled the 64 bit engine and the script worked. Though not exactly. It doesn't fail, but doesn't paste in either, but the paste button works when the email is brought up for preview.


[EDIT]:  let the laptop have a good night's sleep and it works perfectly.