{"id":881,"date":"2024-01-16T23:59:35","date_gmt":"2024-01-16T14:59:35","guid":{"rendered":"https:\/\/web.cloudfree.jp\/journal\/?p=881"},"modified":"2024-01-21T01:04:45","modified_gmt":"2024-01-20T16:04:45","slug":"excel%e3%81%8b%e3%82%89%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1powershell-net%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa","status":"publish","type":"post","link":"https:\/\/web.cloudfree.jp\/journal\/excel%e3%81%8b%e3%82%89%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1powershell-net%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa\/","title":{"rendered":"Excel\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1(PowerShell+.Net\u30e9\u30a4\u30d6\u30e9\u30ea)"},"content":{"rendered":"<h3 class=\"wp-block-post-title\">Excel\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1(PowerShell+.Net\u30e9\u30a4\u30d6\u30e9\u30ea)<\/h3>\n\n\n<p class=\"has-tertiary-color has-text-color has-background has-small-font-size\" style=\"background-color:#8d8dd8;margin-top:0;margin-right:0;margin-bottom:0;margin-left:0;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0\">2024-01-16 \u8a18\u8f09<br>\u6982\u8981 : PowerShell+.Net\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u5a01\u529b\u3092\u8a66\u3059\u305f\u3081Excel\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3057\u3066\u307f\u307e\u3059<br>Keyword : PowerShell, WshShell, System.Net.Mail.SmtpClient, sendmail, VBA, Excel<\/p>\n\n\n\n<p>VBScript\u306f\u5ec3\u6b62\u4e88\u5b9a\u3067\u3059\u304c\u3001\u305d\u306e\u4ee3\u66ff\u3068\u76ee\u3055\u308c\u3066\u3044\u308bPowerShell+.Net\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u308c\u3070\u3001\u307b\u307c\u306a\u3093\u3067\u3082\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3068\u671f\u5f85\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br>VBScript+COM\u3067\u3082\u3001\u307b\u307c\u306a\u3093\u3067\u3082\u3067\u304d\u305f\u308f\u3051\u3067\u3059\u304c\u3001\u521d\u671f\u8a2d\u5b9a\u3067\u52d5\u3044\u3066\u3057\u307e\u3046\u306e\u304c\u30a6\u30a4\u30eb\u30b9\u306e\u6e29\u5e8a\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3001\u3068\u3044\u3046\u53cd\u7701\u304b\u3089\u3001PowerShell\u306f\u521d\u671f\u8a2d\u5b9a\u3067\u306f\u52d5\u304b\u306a\u3044\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u305d\u3046\u3067\u3059\u3002<br><br>\u300c\u671f\u5f85\u3055\u308c\u3066\u3044\u307e\u3059\u300d\u3068\u66f8\u304d\u307e\u3057\u305f\u304c\u672a\u6765\u306e\u8a71\u3067\u306f\u306a\u304f\u3001\u305a\u3063\u3068\u6614\u304b\u3089\u3044\u3064\u3067\u3082\u4f7f\u3048\u3066\u3044\u305f\u306e\u3067\u3059\u3002<br>\u3067\u306f\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<br><br>Excel\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3002<br><br>\u3053\u308c\u306f\u666e\u901a\u3001Outlook.Application\u306b\u4efb\u305b\u308b\u306e\u304cOffice\u6d41\u3002<br>.Net\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u306f\u3001\u30e1\u30fc\u30eb\u3092\u53d7\u4fe1\u3057\u3066\u8aad\u3093\u3067\u3001\u3068\u3044\u3046\u3088\u3046\u306a\u30e1\u30fc\u30e9\u30fc\u7684\u306a\u51e6\u7406\u307e\u3067\u306f\u3067\u304d\u306a\u3044\u3051\u3069\u3001\u9001\u4fe1\u3060\u3051\u306a\u3089sendmail\u3059\u308b\u3088\u3046\u306b\u30b5\u30af\u3063\u3068\u3067\u304d\u308b\u305d\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Public Sub SendMail(ByVal sTo As String, ByVal sSubject As String, ByVal sBody As String)\n    Dim wsh As New IWshRuntimeLibrary.WshShell &#39;CreateObject(&quot;WScript.Shell&quot;)\n    Dim sCmd  As String\n    \n    sCmd = &quot;powershell.exe -command &quot; & Chr(34) & &quot;& { &quot;\n    sCmd = sCmd & &quot;[reflection.assembly]::loadwithpartialname(&#39;System.Net.Mail.SmtpClient&#39;)&quot;\n    sCmd = sCmd & &quot;; $from = &#39;\uff1c\u9001\u4fe1\u5143\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\uff1e&#39;&quot;\n    sCmd = sCmd & &quot;; $smtpclient = New-Object System.Net.Mail.SmtpClient(&#39;smtp.gmail.com&#39;, 587)&quot;\n    sCmd = sCmd & &quot;; $smtpclient.EnableSsl = $true&quot;\n    sCmd = sCmd & &quot;; $smtpclient.Credentials = New-Object System.Net.NetworkCredential($from, &#39;\uff1capp-password\uff1e&#39;)&quot;\n    sCmd = sCmd & &quot;; $smtpclient.Send($from, &#39;%TO%&#39;, &#39;%SUBJECT%&#39;, &#39;%BODY%&#39;)&quot;\n    sCmd = sCmd & &quot; }&quot; & Chr(34)\n    \n    sCmd = Replace(sCmd, &quot;%TO%&quot;, sTo)\n    sCmd = Replace(sCmd, &quot;%SUBJECT%&quot;, sSubject)\n    sCmd = Replace(sCmd, &quot;%BODY%&quot;, sBody)\n    \n    wsh.Run sCmd, 0 &#39; 0=Window\u975e\u8868\u793a\nEnd Sub\n<\/code><\/pre><\/div>\n\n\n\n<p>GMail\u3067\u30a2\u30d7\u30ea\u30d1\u30b9\u30ef\u30fc\u30c9\u53d6\u5f97\u6e08\u307f\u306e\u30b1\u30fc\u30b9\u3002<br>\u5b9b\u5148\uff11\u4ef6\u306e\u307f\u3001\u3067\u30c6\u30b9\u30c8\u7528\u3067\u3059\u3002<br>\u5b9f\u969b\u3001\u30b5\u30af\u3063\u3068\u9001\u308c\u307e\u3057\u305f\u3002\uff11\uff14\u884c\u3067\u3002<br><br>14\u884c\u3063\u3066\u591a\u3044\u3067\u3059\u3051\u3069(^^; <br>\u3067\u3082\u5727\u7e2e\u3057\u305f\u30894\u884c\u3067\u3059\u3002<br>\u305d\u3053\u3088\u308a\u3082\u300e\u7d50\u5c40WshShell\u4f7f\u3063\u3066\u308b\u306e?\u300f\u3068\u3044\u3046\u70b9\u304c\u30ca\u30f3\u3067\u3059\u3051\u3069\u3002<br><br>New IWshRuntimeLibrary.WshShell<br>\u3059\u308b\u3088\u3046\u306b<br>PowerShell\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308c\u305f\u3089\u30b9\u30de\u30fc\u30c8\u306a\u306e\u3067\u3059\u304c\u3001\u305d\u3046\u3059\u308b\u3068WshShell\u3092\u901a\u3057\u3066PowerShell\u3082\u30a6\u30a4\u30eb\u30b9\u306e\u6e29\u5e8a\u3068\u3044\u3046\u30ec\u30c3\u30c6\u30eb\u3092\u8cbc\u3089\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u305d\u3046\u306f\u3055\u305b\u306a\u304b\u3063\u305f\u306e\u3067\u3057\u3087\u3046\u3002<br><br><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>.Net\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u6a5f\u80fd\u3092PowerShell\u3092\u901a\u3058\u3066Excel\u304b\u3089\u4f7f\u3046\u8a66\u307f\u306f\u30b5\u30af\u3063\u3068\u6210\u529f\u3057\u307e\u3057\u305f<\/p>\n","protected":false},"author":1,"featured_media":882,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"wp-custom-template-x24-index","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[148,89,110,86,106,45],"_links":{"self":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts\/881"}],"collection":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/comments?post=881"}],"version-history":[{"count":0,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts\/881\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/media\/882"}],"wp:attachment":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/media?parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/categories?post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/tags?post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}