[HTA+VBS]電話番御用達スクリプト

概要

電話不在時メモをメールで送ります。
ほぼ定型文なんで、宛先・先方名・対応を選んで送るだけ。
新しい先方名は自動追加します。フリー入力欄もあります。

登録:2008/07/12・更新:2008/09/06

良い子のお約束

このページに書かれている事を実行して、何が起こっても私は知りません。
まぁ、このページに到達された方なら大丈夫でしょうけど(^o^)。

環境とか

使い方

スクリプト re976001.hta の固定値をご自分の環境に合わせて変更し、起動して下さい。
宛先定義ファイル re976002.txt は、表示名とメアドをタブで区切って登録して下さい。
先方名ファイルは、登録した内容そのままで使用します。新規の先方様登録時には、電話番号も合わせて登録します。
BASP21 は、自力でインストールして下さい。

スクリプトのソース

[re976001.hta:ここから]======================================================================

<html>
<head>
    <HTA:APPLICATION
        APPLICATIONNAME="電話番"
        ICON="winchat.exe" 
        SCROLL="no"
    />
    <style type="text/css">
    <!--
        body,select,input,td    {
            font-family         : monospace;
        }
        h1  {
            display             : none;
            margin-top          : 0.5em;
            padding-top         : 0.2em;
            padding-bottom      : 0.2em;
            margin-bottom           : 0.5em;
            padding-left        : 1em;
            color               : #3333ff;
            background-color    : #99ffff;
            font-size           : 130%;
        }
        p   {
            margin-top          : 0 em;
            padding-top         : 0 em;
            padding-bottom      : 0 em;
            margin-bottom       : 0 em;
        }
        textarea.data_list  {
            font-family         : monospace;
            font-size           : 150%;
        }
        textarea.log_list   {
            font-family         : monospace;
            font-size           : 110%;
        }
        input.pc_file   {
            width               : 23em;
        }
        input.text  {
            font-family         : monospace;
            width               : 8em;  
            font-size           : 150%;
        }
        pre         {
            display             : none;
            font-size           : 50%;
        }
        span.UL {
            text-decoration     : underline;
        }
    -->
    </style>

</head>
<body onload="S_onload_proc()" onkeyup="S_Keyup_on_body()">
<form id="form_main" onsubmit="">
<h1 id="page_title">タイトル</h1>
<table>
    <tr>
        <td >
            (<span class="UL">1</span>)
            <select id="to" size="16" accesskey='1'>
            </select>
            へ。
            <p id="aisatsu">お疲れ様です。まるふ研究所です。</p>
        </td>
        <td rowspan="2">
<p>
    (<span class="UL">3</span>)
    『<input class="text" id="Customer_company" value="" accesskey='3'/>』の『<input class="text" id="Customer_name" value="" />』様
</p>
<p>
    (<span class="UL">4</span>)
    <select id="Customer_list" size="17" accesskey='4' onkeyup="S_Keyup_on_Customer_list()" onChange="S_onChange_Customer_list()">
    </select>
    <span id="log_Customer_tel"></span>
    <br><span id="Sub_postfix">より、お電話がありました。</span>
</p>
        </td>

    </tr>
    <tr>
        <td>
            <input type=button onclick="S_get_time()" value="(2)時刻取得"  accesskey='2' />
            <br>
            <span id="tel_time"></span>
        </td>
    </tr>
</table>

<hr />
<p>
    <input name="talk_opt" id="talk_opt-0" type="radio" value="0" accesskey='5' checked><label for="talk_opt-0">(<span class="UL">5</span>)
    <span id="talk-0">電話があった事をお伝え下さい、との事です。</span></label>
</p>
<p>
    <input name="talk_opt" id="talk_opt-1" type="radio" value="1" accesskey='6' ><label for="talk_opt-1">(<span class="UL">6</span>)
    <span id="talk-1">特に用件は伺っておりません。</span></label>
</p>
<p>
    <input name="talk_opt" id="talk_opt-2" type="radio" value="2" accesskey='7' ><label for="talk_opt-2">(<span class="UL">7</span>)
    <span id="talk-2">また、お電話頂けるそうです。</span></label>
</p>
<p>
    <input name="talk_opt" id="talk_opt-3" type="radio" value="3" accesskey='8' ><label for="talk_opt-3">(<span class="UL">8</span>)
    <span id="talk-3">こちらから、電話を頂きたいとの事です。</span>
    <input class="text" id="Customer_tel" value="" /></label>
</p>
<p>
    <input name="talk_opt" id="talk_opt-9" type="radio" value="9" accesskey='9' ><label for="talk_opt-9">(<span class="UL">9</span>)
    <span id="talk-9"><定型文なし></span></label>
</p>
<p>
    (<span class="UL">0</span>)
    <textarea class="log_list" id="naiyo" rows="5" cols="70" accesskey='0' ></textarea>
</p>
<hr />
<div>
    <input id="send_mail" type=button onclick="S_send_mail()" value="(F10)メール送信" />
</div>
<pre id="musubi">
以上、よろしくお願いいたします。

- -
まるふ研究所 krsna@devilsummoner.net
</pre>

</form>

<script language="VBScript">
    option explicit

    'ウィンドウ初期値
    Const C_title_text = "電話番 V1.2"
    Const C_window_width    = 750
    Const C_window_height   = 630
    'ネットワーク設定
    Const C_smtp_server     = "mailserver:25:30"
    Const C_mail_from       = "krsna@devilsummoner.net"

    Const C_X_Mailer        = "Denwaban V1.2"

    Const C_Denwaban_to_file    = "re976002.txt"
    Const C_Denwaban_Cust_file  = "re976003.txt"
    Const C_Denwaban_Cust_temp_file = "re976004.tmp"

    dim rt,i
'--------------------------------------------------------------------------------
' Bodyでのキーアップイベント → F10 でメール送信
sub S_Keyup_on_body()

    if window.event.keyCode = 121 then  'F10
        document.all("send_mail").onclick
    end if

end sub
'--------------------------------------------------------------------------------
' 客先リストファイルの更新
sub S_Update_Denwaban_Cust_file(P_Customer_Str,P_Customer_tel)

    dim L_fso,L_old_file,L_new_file
    dim L_ReadLine

    set L_fso = CreateObject("Scripting.FileSystemObject")

    if L_fso.FileExists(C_Denwaban_Cust_file) then
        Set L_old_file = L_fso.OpenTextFile(C_Denwaban_Cust_file,1)
        Set L_new_file = L_fso.OpenTextFile(C_Denwaban_Cust_temp_file,2,true)
        '新規顧客の登録
        L_new_file.WriteLine P_Customer_Str & vbtab & P_Customer_tel
        '後は、読んだ順番に登録
        Do While L_old_file.AtEndOfLine <> True
            L_ReadLine = L_old_file.ReadLine
            if L_ReadLine <> P_Customer_Str then
                L_new_file.WriteLine L_ReadLine
            end if
        Loop
        L_new_file.Close
        L_old_file.Close

        '旧ファイル削除             C_Denwaban_Cust_file
        Call L_fso.DeleteFile(C_Denwaban_Cust_file)
        '新ファイルリネーム         C_Denwaban_Cust_temp_file → C_Denwaban_Cust_file
        Call L_fso.MoveFile( C_Denwaban_Cust_temp_file, C_Denwaban_Cust_file )
    end if
    set L_fso = nothing

end sub
'--------------------------------------------------------------------------------
' 客先リストの変更時の処理
sub S_onChange_Customer_list()

    document.all("log_Customer_tel").innerText = document.all("Customer_list").options(document.all("Customer_list").selectedindex).value

end sub
'--------------------------------------------------------------------------------
' 客先リストのテキストファイル呼び出し
sub S_Keyup_on_Customer_list()

    dim L_Shell,L_Exec

    if window.event.keyCode <> 13 then exit sub     'enter キー以外無視

    set L_Shell = CreateObject("WScript.Shell")
    L_Shell.run (C_Denwaban_Cust_file)
    set L_Shell = nothing

end sub
'--------------------------------------------------------------------------------
' メール送信先リストボックスの初期読み込み
sub S_Load_to_list()
    dim L_file_name
    dim L_fso,L_file
    dim L_option_element
    dim LA_temp_array

    'ファイル一覧を読みながら、オプションの追加
'   L_file_name = left(document.location.pathname,InStrRev(document.location.pathname,"\")) & C_Denwaban_Cust_file
    L_file_name = C_Denwaban_to_file
    set L_fso = CreateObject("Scripting.FileSystemObject")

    if L_fso.FileExists(L_file_name) then
        Set L_file = L_fso.OpenTextFile(L_file_name,1)
        Do While L_file.AtEndOfLine <> True
            LA_temp_array = split(L_file.ReadLine,vbtab)
            'オプションの作成
            set L_option_element    = document.createElement("OPTION")
            L_option_element.value  = trim(LA_temp_array(1))
            L_option_element.text   = trim(LA_temp_array(0))
            'オプションの追加
            document.all("to").options.add(L_option_element)
        Loop
        L_file.Close
        set L_file = nothing
    end if
    set L_fso = nothing

    document.all("to").selectedindex = 0

end sub
'--------------------------------------------------------------------------------
' 電話相手リストボックスの初期読み込み
sub S_Load_Customer_list()
    dim L_file_name
    dim L_fso,L_file
    dim L_option_element
    dim LA_Customer

    'オプションの初期化
    if document.all("Customer_list").options.length > 0 then
        For i = document.all("Customer_list").options.length - 1 To 0 step -1
            document.all("Customer_list").options.remove(i)
        Next
    end if

    'ファイル一覧を読みながら、オプションの追加
    L_file_name = C_Denwaban_Cust_file
    set L_fso = CreateObject("Scripting.FileSystemObject")

    if L_fso.FileExists(L_file_name) then
        Set L_file = L_fso.OpenTextFile(L_file_name,1)
        Do While L_file.AtEndOfLine <> True
            'オプションの作成
            set L_option_element    = document.createElement("OPTION")
            LA_Customer = split(L_file.ReadLine,vbtab)
            if UBound(LA_Customer) > 0 then
                L_option_element.value  = trim(LA_Customer(1))
            else
                L_option_element.value  = ""
            end if
            L_option_element.text   = trim(LA_Customer(0))
            'オプションの追加
            document.all("Customer_list").options.add(L_option_element)
        Loop
        L_file.Close
        set L_file = nothing
    end if
    set L_fso = nothing

    document.all("Customer_list").selectedindex = 0

end sub
'--------------------------------------------------------------------------------
sub S_send_mail()
    dim L_mail
    dim L_smtp_server,L_mail_to,L_mail_from,L_mail_sub,L_mail_body
    dim L_Customer_company,L_Customer_name,L_Customer_Str
    dim L_mail_to_MSG_txt

    '受電時刻の省略値設定
    if document.all("tel_time").innerText = "" then
        Call S_get_time()
    end if

    'メール送信設定
    L_smtp_server   = C_smtp_server
    L_mail_from     = C_mail_from
    'メール送信先設定
    L_mail_to_MSG_txt   = document.all("to").value
    L_mail_to       = document.all("to").value & vbtab & "bcc" & vbtab & C_mail_from
    L_mail_to       = L_mail_to & vbtab & "bcc" & vbtab & C_mail_from
    L_mail_to       = L_mail_to & vbtab & ">X-Mailer: " & C_X_Mailer

    '件名編集
    L_mail_sub = document.all("tel_time").innerText

    L_Customer_Str = ""
    L_Customer_company = trim(document.all("Customer_company").value)
    L_Customer_name = trim(document.all("Customer_name").value)
    if ( L_Customer_company <> "" ) and ( L_Customer_name <> "" ) then
        L_Customer_Str = "『" & L_Customer_company & "』の『" & L_Customer_name & "』様"
        L_mail_sub = L_mail_sub & L_Customer_Str
    elseif ( L_Customer_company = "" ) and ( L_Customer_name <> "" ) then
        L_Customer_Str = "『" & L_Customer_name & "』様"
        L_mail_sub = L_mail_sub & L_Customer_Str
    elseif ( L_Customer_company <> "" ) and ( L_Customer_name = "" ) then
        L_Customer_Str = "『" & L_Customer_company & "』様"
        L_mail_sub = L_mail_sub & L_Customer_Str
    else
        L_mail_sub = L_mail_sub & document.all("Customer_list").options(document.all("Customer_list").selectedindex).text
    end if
    L_mail_sub = L_mail_sub & trim(document.all("Sub_postfix").innerText)

    '本文設定
    L_mail_body = document.all("to").options(document.all("to").selectedindex).text & "へ。"
    L_mail_body = L_mail_body & vbcrlf & document.all("aisatsu").innerText
    L_mail_body = L_mail_body & vbcrlf & vbcrlf & L_mail_sub

    if ( document.all.talk_opt(0).checked = true ) then
        L_mail_body = L_mail_body & vbcrlf & document.all("talk-0").innerText
    elseif ( document.all.talk_opt(1).checked = true ) then
        L_mail_body = L_mail_body & vbcrlf & document.all("talk-1").innerText
    elseif ( document.all.talk_opt(2).checked = true ) then
        L_mail_body = L_mail_body & vbcrlf & document.all("talk-2").innerText
    elseif ( document.all.talk_opt(3).checked = true ) then
        L_mail_body = L_mail_body & vbcrlf & document.all("talk-3").innerText
        if document.all("Customer_tel").value <> "" then
            L_mail_body = L_mail_body & vbcrlf & "電話番号:" & document.all("Customer_tel").value
        end if
    else
    end if

    if trim(document.all("naiyo").value) <> "" then
        L_mail_body = L_mail_body & vbcrlf & trim(document.all("naiyo").value)
    end if
    L_mail_body = L_mail_body & vbcrlf & vbcrlf & document.all("musubi").innerText

    '確認ダイアログを出す。
    rt = msgbox(L_mail_to_MSG_txt & vbcrlf & L_mail_body,1)
    if rt = 2 then exit sub     'キャンセルなら抜ける

    Set L_mail = CreateObject("basp21")
    rt = L_mail.SendMail(L_smtp_server,L_mail_to,L_mail_from, L_mail_sub,L_mail_body,"")
    if rt <> "" then    ' エラーチェック
        msgbox rt
        exit sub
    end if  

    '客先リストファイルの更新
    if L_Customer_Str <> "" then
        Call S_Update_Denwaban_Cust_file(L_Customer_Str,document.all("Customer_tel").value)
        Call S_Load_Customer_list()
        Call S_onChange_Customer_list()
    end if

    '最後に送信時刻等は消しときます。
    document.all("tel_time").innerText = ""
    document.all("Customer_company").value = ""
    document.all("Customer_name").value = ""
    document.all("Customer_tel").value = ""
    document.all("naiyo").value = ""

    msgbox "送信しました。"

end sub
'--------------------------------------------------------------------------------
sub S_get_time()
    dim L_date,L_time

    L_date = date
    L_time = time
    document.all("tel_time").innerText = right("00" & datepart("m",L_date),2) & "/" & right("00" & datepart("d",L_date),2)  & " " & right("00" & datepart("h",L_time),2) & ":" & right("00" & datepart("n",L_time),2) & " 頃、"

end sub
'--------------------------------------------------------------------------------
sub S_onload_proc()

    document.title = C_title_text
    document.all("page_title").innerText = C_title_text
    rt = window.resizeTo(C_window_width,C_window_height)

    Call S_Load_to_list()
    Call S_Load_Customer_list()
    Call S_onChange_Customer_list()

end sub
</script>
</body></html>

[re976001.hta:ここまで]======================================================================

[re976002.txt:ここから]======================================================================

クリシュナさん <tab> krsna@devilsummoner.net
メタトロン君   <tab> metatron@devilsummoner.net

[re976002.txt:ここまで]======================================================================

[re976003.txt:ここから]======================================================================

『テストの人』<tab>TEST-tel
『本社』の『社長』様<tab>090-9999-0000

[re976003.txt:ここまで]======================================================================