2012年1月19日木曜日

VB.NETからNotesDBの新規文書を作成する

自分の環境では「参照の追加」は不要ですが、環境によっては必要かもしれませんので、ご注意を。

        Dim session As Object
        Dim db As Object
        Dim doc As Object

        Dim strDominoServer As String
        Dim strDBName As String

        'NotesDB接続初期化
        ' ***NotesDBからの読み込み
        ' *** セッションの確立
        session = CreateObject("Notes.NotesSession")

        ' *** ノーツDBの取得
        db = session.GetDatabase(strDominoServer, strDBName)

        If (Not db.IsOpen()) Then
            ' *** エラーメッセージの表示
            MsgBox("データベースが見つかりませんでした", vbOKOnly + vbCritical)
            GoTo load_exit
        End If

        doc = db.CreateDocument

        doc.ReplaceItemValue("Form", "MainDoc")
        doc.ReplaceItemValue("Subject", “テスト”)

        Call doc.Save(True, True)

load_exit:
        ' *** オブジェクトの破棄
        db = Nothing
        session = Nothing

2012年1月5日木曜日

スクリプトによるNotesDBからCSV書き出し

「ファイル」-「書き出し」からでもCSV書き出しが出来ますが、スクリプトによるCSV書き出しのサンプルコードです。

Sub Click(Source As Button)
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    Dim Code, Section, Name As Variant
    Dim FileName As String   
    Dim FileNum As Long
    Dim i As Integer

    Set db = s.CurrentDatabase
    Set view = db.GetView("EmployeeView")
    Set doc = view.GetFirstDocument

    FileName = "C:\Employee.CSV"
    FileNum = Freefile '空いている番号を取得する
    Open FileName For Output As #FileNum '書き込みモードで開く

    Do Until doc Is Nothing
        Code = doc.GetItemValue("Code")
        Section = doc.GetItemValue("Section")
        Name = doc.GetItemValue("Name")
        Print #FileNum , & _
        Code(0) & "," & _
        Section(0) & "," & _
        Name(0)
        Set doc = view.GetNextDocument(doc)
    Loop

    Close #FileNum 'ファイルを閉じる

End Sub

NotesDBのデータを直接Excelに書き出す

ビューをCSVに書き出す機能は標準で用意されていますが、以下のスクリプトを参考にすれば、直接Excelに書き出すことが出来ます。(当然のことですが、Excelがインストールされていないと使えません。)
以下のスクリプトはビューのボタンに配置したときのサンプルです。

Sub Click(Source As Button)
    Dim s As New NotesSession
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim view As NotesView
    Dim XLApp As Variant
    Dim XLBook As Variant
    Dim Code, Section, Name As Variant
    Dim x As Integer
    Set db = s.CurrentDatabase
    Set view = db.GetView("EmployeeView")
    Set doc = view.GetFirstDocument
    Set XLApp = createobject("Excel.Application")
    If ( XLApp Is Nothing ) Then
        Messagebox "Excelが見つかりません。
                             Excelが正しくインストールされていることを
                             確認してください。", MB_OK, "エラー"
        Exit Sub
    End If
    XLApp.Workbooks.add
    Set XLBook = XLApp.ActiveWorkbook
    XLApp.Visible=True
'見出し
    XLBook.Worksheets( 1 ).Cells( 1, 1 ).Value="社員コード"
    XLBook.Worksheets( 1 ).Cells( 1, 2 ).Value="部署"
    XLBook.Worksheets( 1 ).Cells( 1, 3 ).Value="氏名"
    x = 2
    Do Until doc Is Nothing
        Code = doc.GetItemValue("Code")
        Section = doc.GetItemValue("Section")
        Name = doc.GetItemValue("Name")
        XLBook.Worksheets( 1 ).Cells( x, 1 ).Value = Code(0)
        XLBook.Worksheets( 1 ).Cells( x, 2 ).Value = Section(0)
        XLBook.Worksheets( 1 ).Cells( x, 3 ).Value = Name(0)
        x = x + 1
        Set doc = view.GetNextDocument(doc)
    Loop
End Sub

2011年11月23日水曜日

Firefox Googleツールバー代替方法

Firefox5.0以降、 Googleツールバーが標準では使えなくなってしまいました。
いろいろなサイトで代替方法を紹介してありますが、自分的にはFirefox標準の検索バーをGoogleツールバーなみに強化出来れば十分なので、その方法を紹介します。

1.検索バーの横に履歴表示ボタンを追加する
userChrome.cssに以下のコードを追加します。なければ新規に作成します。

/* 検索バーの右側に履歴を出すボタンを表示 */
#searchbar .autocomplete-history-dropmarker {
    display: -moz-box !important;
    -moz-binding: url("chrome://global/content/bindings/autocomplete.xml#history-dropmarker");
}


userChrome.cssは以下の場所にあります。
Windows 2000, XP %APPDATA%\Mozilla\Firefox\Profiles\(英数字の羅列).(プロファイル名)\chrome\userChrome.css
Windows Vista, 7 %USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\(英数字の羅列).(プロファイル名)\Chrome\userChrome.css

履歴表示

2.アドオン「Searchbar Autocomplete Order」を導入する
こちらのアドオンで検索履歴を検索順に並べかえることが出来るようになります。
https://addons.mozilla.org/ja/firefox/addon/searchbar-autocomplete-order/
Searchbar Autocomplete Order

3.アドオン「SearchWP」を導入する
このアドオンで、検索バーから「ページ内検索」と「ハイライト表示」が出来るようになります。
https://addons.mozilla.org/ja/firefox/addon/searchwp/
SearchWP

4.アドオン「SearchBox Sync」を導入する
このアドインで検索バーと検索エンジンのキーワードを同期することが出来るようになります。
https://addons.mozilla.org/ja/firefox/addon/searchbox-sync/
SearchBox Sync

2011年11月22日火曜日

ログオンスクリプトでスクリーンセイバーの伝言板を統一する方法

企業内でスクリーンセイバーの伝言板を統一したいというニーズは有るかと思います。
それに対応するためのVBスクリプトを書きました。
サーバーに共有フォルダを作成し、「伝言板.txt」を保存することで、表示する文字列を簡単に変更することが可能です。

Dim WshShell

'コンフィルファイル名
configname="\\Server\伝言板.txt"

'値を代入する変数と、検索するキーと、デフォルト値
Value = readconf("TXT","0")
'Wscript.echo Value

Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Control Panel\Screen Saver.Marquee\Text",Value, "REG_SZ"
'終了
WScript.quit

'読みとり関数
Private Function readconf(key,def)

  Dim c,conf,LD

  Set c=CreateObject("Scripting.FileSystemObject")
  Set conf=c.OpenTextFile(configname)

  readconf=def
  key=key & "="

  Do While conf.AtEndOfStream <> True

    LD = conf.readline
    If (left(trim(LD),1)<>"#") and (Len(Trim(LD))<>0) then
      If len(key) < len(LD) then
        If left(LD,len(key))=key then
          readconf=right(LD,len(LD)-Len(key))
        End if
      End if
    End if

  Loop

  conf.close
  set c = nothing

End Function

伝言板.txtの書き方

TXT=こんにちは

VB.NETからNotesDBへアクセスするサンプルコード

自分の環境では「参照の追加」は不要ですが、環境によっては必要かもしれませんので、ご注意を。

        Dim session As Object
        Dim db As Object
        Dim view As Object
        Dim doc As Object

        Dim strDominoServer As String
        Dim strDBName As String
        Dim strViewName As String

        Dim NSubject As Object
        Dim strSubject As String

        ' ***NotesDBからの読み込み
        ' *** セッションの確立
        session = CreateObject("Notes.NotesSession")

        ' *** ノーツDBの取得
        db = session.GetDatabase(strDominoServer, strDBName)
        If (Not db.IsOpen()) Then
            ' *** エラーメッセージの表示
            MsgBox("データベースが見つかりませんでした", vbOKOnly + vbCritical)
            GoTo load_exit
        End If

        ' *** ビューの取得
        view = db.GetView(strViewName)
        If (view Is Nothing) Then
            ' *** エラーメッセージの表示
            MsgBox("ビューが見つかりませんでした", vbOKOnly + vbCritical)
            GoTo load_exit
        End If

        ' *** ビューより最初の文書を取得
        doc = view.GetFirstDocument()

        ' *** ビューより全文書を読み込むまでループ
        Do While (Not (doc Is Nothing))
            'タイトル
            NSubject = doc.GetItemValue("Subject")
            strSubject = NSubject(0).ToString

            doc = view.GetNextDocument(doc)
        Loop

load_exit:

        ' *** オブジェクトの破棄
        db = Nothing
        session = Nothing

2011年11月10日木曜日

IE8のメニューバーをIE6風にアドレスバーの上に表示するVBスクリプト

IE1IE2

Dim WshShell

Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Toolbar\WebBrowser\ITBar7Position",1, "REG_DWORD"

WScript.Echo("変更終了")

WScript.quit

上記のVBスクリプトを拡張子「vbs」(例:ie.vbs)で保存するとそのまま使えます。