2011年5月30日月曜日

Excel VBA マクロ実行時の画面のチラツキをなくす方法

マクロを実行している際に、画面がチラチラして
気になるので制御できないか調べてみた。

マクロの Sub または、 Function を書いた行の次の行へ

Application.ScreenUpdating = False

を記述する。

チラツキがなくなります。

マクロが動いている間は、画面の更新を行わないという
設定みたいです。

2011年5月29日日曜日

Excel VBA セルの色を変更

A1セルの色を赤くする方法

// RGB関数を使用して設定
Range("A1").Interior.Color = RGB(255, 0, 0)
// ColorIndexを使用して設定
Range("A1").Interior.ColorIndex = 3

2011年5月28日土曜日

Excel VBA 最終行の取得方法

最終行の番号を取得する方法
ActiveSheet.Cells(ActiveSheet.Cells.Rows.Count, 1).End(xlUp).Row

2011年5月27日金曜日

JAVA ファイル分割処理

ファイルを指定した行数で分割するクラスです。
大きなサイズのファイルとか、テキストエディターで
開けなかったりする場合に、使用すると便利です。

public static void main(String[] args) {
}
を実装して使ってみてください。


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class DivideFileClass {
    public boolean divideFile(File fi, int row) {
        return this.divideFile(fi, row, "UTF-8", "UTF-8");
    }
    public boolean divideFile(File fi, int row, String iCode, String oCode) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        FileInputStream fis = null;
        FileOutputStream fos = null;
        InputStreamReader isr = null;
        OutputStreamWriter osw = null;
        String line = null;
        int count = 0;
        int fileNo = 1;
        try {
            fis = new FileInputStream(fi);
            isr = new InputStreamReader(fis, iCode);
            br = new BufferedReader(isr);
            fos = new FileOutputStream(fi.getPath() + String.valueOf(fileNo));
            osw = new OutputStreamWriter(fos, oCode);
            bw = new BufferedWriter(osw);
            while ((line = br.readLine()) != null) {
                bw.write(line);
                bw.newLine();
                if (count == row) {
                    bw.close();
                    fileNo++;
                    fos = new FileOutputStream(fi.getPath() + String.valueOf(fileNo));
                    osw = new OutputStreamWriter(fos, oCode);
                    bw = new BufferedWriter(osw);
                    count = 0;
                }
                count++;
            }
            bw.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }
}

2011年5月26日木曜日

JAVA ファイル結合処理

複数のテキストファイルを1つのファイルにするクラスです。
ツールとして作成しているため、効率とか考えてません。

public static void main(String[] args) {
}
を実装して使ってみてください。


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
public class ConcatFileClass {
    /**
     * 指定されたディレクトリ(dir)配下のファイルを1つのファイル(f)に結合します。
     * @param dir File
     * @return boolean true : succeeded, false : failed
     */
    public boolean execute(File dir, File f) {
        return this.execute(dir, f, "SJIS", "SJIS");
    }
    public boolean execute(File dir, File f, String fic, String foc) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        File[] files = null;
        String line = null;
        int count = 0;
        if (dir == null || f == null) {
            System.out.println("パラメータに誤りがあります。");
            return false;
        } else if (dir.isFile()) {
            System.out.print(dir.toString());
            System.out.println("は、ディレクトリではありません。");
            return false;
        } else if (f.isDirectory()) {
            System.out.print(f.toString());
            System.out.println("は、ファイルではありません。");
            return false;
//      } else if (f.canWrite()) {
//          System.out.print(f.toString());
//          System.out.println("は、書き込み可能ファイルではありません。");
//          return false;
        } else if (!dir.exists()) {
            System.out.println("ディレクトリが存在しません。");
            return false;
        }
        try {
            files = dir.listFiles();
            if (files == null || files.length == 1) {
                System.out.println("結合するファイルが存在しません。");
                return false;
            }
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), foc));
            count = files.length;
            for (int i = 0; i < count; i++) {
                br = new BufferedReader(new InputStreamReader(new FileInputStream(files[i]), fic));
                while ((line = br.readLine()) != null) {
                    bw.write(line);
                    bw.newLine();
                }
                br.close();
            }
            bw.close();
        } catch (FileNotFoundException e) {
            System.out.println("ファイルが見つかりません。");
            return false;
        } catch (UnsupportedEncodingException e) {
            System.out.println("文字コードがサポートされていません。");
            return false;
        } catch (IOException e) {
            System.out.println("入出力でエラーが発生しました。");
            return false;
        }
        return true;
    }
}

2011年5月25日水曜日

JAVA ファイルの文字コード変換

ファイルの文字コードを変換するクラスです。
ツールとして作成しているため、効率とか考えてません。

public static void main(String[] args) {
}
を実装して使ってみてください。


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
public class ChangeCodeClass {
    /**
     * 入力ファイル(input)の文字コード(fic)を文字コード(foc)で出力ファイル(output)を作成する
     * @param fi     input file
     * @param fic input file's code
     * @param fo     output file
     * @param foc output file's code
     * @return boolean true : succeeded, false : failed
     */
    public boolean changeCode(File fi, String fic, File fo, String foc) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        String line = null;
        if (fi == null || fo == null || fic == null || fic.equals("") || foc == null || foc.equals("")) {
            System.out.println("パラメータに誤りがあります。");
            return false;
        } else if (fi.isDirectory() || fo.isDirectory()) {
            System.out.println("ファイルではありません。");
            return false;
//      } else if (!fi.canRead() || !fo.canWrite()) {
//          System.out.println("読み込みまたは、書き込みが出来ません。");
//          return false;
        } else if (!fi.exists()) {
            System.out.println("入力ファイルが存在しません。");
            return false;
        } else if (fo.exists()) {
            System.out.println("出力ファイルと同名のファイルが存在します。");
            return false;
        } else if (fi.getPath().equals(fo.getPath())) {
            System.out.println("入力ファイルと出力ファイルが同一のパスです。");
            return false;
        }
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(fi), fic));
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fo), foc));
            while ((line = br.readLine()) != null) {
                bw.write(line);
                bw.newLine();
            }
            bw.close();
            br.close();
    
        } catch (FileNotFoundException e) {
            System.out.println("ファイルが見つかりません。");
            return false;
        } catch (UnsupportedEncodingException e) {
            System.out.println("文字コードがサポートされていません。");
            return false;
        } catch (IOException e) {
            System.out.println("入出力でエラーが発生しました。");
            return false;
        }

        return true;
    }
}

2011年5月24日火曜日

Windows フォルダの権限を確認したい場合のコマンド

[windowsボタン] + R

ファイル名を指定して実行ダイアログが表示される。

cmd

と入力し、Enter!!

コマンドプロンプトが立ち上がるので

cd "移動しだいパスを指定"

for /F %A in ('dir /b /ad') do cacls "%A" /C

2011年5月23日月曜日

Excel VBA ファイル選択ダイアログ表示編

Public Function fileSelect(fpath As String)
    Set FS = CreateObject("Scripting.FileSystemObject")
    file = fpath
    With Application.FileDialog(msoFileDialogFilePicker)
        If fpath <> "" And FS.FileExists(fpath) Then
            .InitialFileName = FS.GetParentFolderName(fpath)
        End If
        If .Show = True Then
           file = .SelectedItems(1)
        End If
    End With
    fileSelect = file
End Function

2011年5月22日日曜日

Eclipse SVN ユーザ情報退避バッチ編

@ECHO OFF
ECHO SVNユーザ情報退避処理
ECHO ユーザ:%USERNAME%
REM 初期設定
SET DASDir="C:\Documents and Settings\%USERNAME%"
SET SVNUsr="C:\Documents and Settings\%USERNAME%\Application Data\Subversion\auth\svn.simple\"
SET 標準="%DASDir%\SVN標準"
SET 管理="%DASDir%\SVN管理"
SET 宛先=""
:START
SET /P INPUT=退避するユーザ(現在の状況)を指定 [1:標準ユーザ 2:管理ユーザ 9:終了] :
IF %INPUT% EQU 1 (
    SET 宛先=%標準%
    GOTO DOCOPY
)
IF %INPUT% EQU 2 (
    SET 宛先=%管理%
    GOTO DOCOPY
)
IF %INPUT% EQU 9 (
    GOTO END
)
SET INPUT=""
GOTO START
:DOCOPY
IF NOT EXIST %標準% (
    ECHO 標準ユーザ情報退避フォルダ作成
    MKDIR %標準%
)
IF NOT EXIST %管理% (
    ECHO 管理ユーザ情報退避フォルダ作成
    MKDIR %管理%
)
ECHO ユーザ情報退避処理
CD %SVNUsr%
COPY ファイル名 %宛先%
:END
PAUSE

2011年5月21日土曜日

Excel VBA Java用定数クラス作成マクロ UTF-8(BOM無)編

<エクセルのレイアウト>

3行目
B列 区分名
C列 値
D列 名称
E列 型(String等)
F列 配列 ○:配列値行番号使用、◎:配列値直接入力使用 
G列 配列値行番号
H列 配列値直接入力


4行目以降 は値

<マクロの内容>


Option Explicit
Private Const 入力開始行 = 4
Private Const 区分名列 = 2
Private Const 値列 = 3
Private Const 名称列 = 4
Private Const 型列 = 5
Private Const 配列列 = 6
Private Const 配列値行番号列 = 7
Private Const 配列値直接入力列 = 8
Private Const 囲む列 = 9
Private Sub CommandButton1_Click()
    Dim maxRow As Integer           ' 最終行番号
    Dim outRow As Integer           ' 出力行
    Dim tmpFileName As String       ' 一時ファイル名
    Dim fileName As String          ' ファイル名
    Dim i, j, k, cnt As Integer
    Dim tmpFile As ADODB.Stream     ' 一時ファイル出力用ストリーム
    Dim readFile As ADODB.Stream    ' ファイル読込用ストリーム
    Dim writeFile As ADODB.Stream   ' ファイル出力用ストリーム
    Dim wStr As String              ' ワーク文字
    Dim 配列値行番号() As String
    Dim 配列値直接入力() As String
    Dim 行番号, 直接入力 As Variant
   
    '最終行取得
    maxRow = ActiveSheet.Range("B65536").End(xlUp).Row
    '入力開始位置確認
    If maxRow < 入力開始行 Then
        MsgBox "値が入力されていません。"
        Exit Sub
    End If
    '一時ファイル出力処理
    Set tmpFile = CreateObject("ADODB.Stream")
    '文字コード設定
    tmpFile.Charset = "UTF-8"
    'ファイルオープン
    tmpFile.Open
    'バッファに出力
    tmpFile.WriteText "/******************************************************************", adWriteLine
    tmpFile.WriteText " * モジュール名", adWriteLine
    tmpFile.WriteText " * " & Range("B1").Value, adWriteLine
    tmpFile.WriteText " *", adWriteLine
    tmpFile.WriteText " * 変更履歴", adWriteLine
    tmpFile.WriteText " *    変更日        変更者    変更概要", adWriteLine
    tmpFile.WriteText " *    YYYY/MM/DD    氏  名   新規作成", adWriteLine
    tmpFile.WriteText " ******************************************************************", adWriteLine
    tmpFile.WriteText " */", adWriteLine
    tmpFile.WriteText "", adWriteLine
    tmpFile.WriteText "package jp.co.xxx.common.constant;", adWriteLine
    tmpFile.WriteText "", adWriteLine
    tmpFile.WriteText "/**", adWriteLine
    tmpFile.WriteText " * 共通定数", adWriteLine
    tmpFile.WriteText " * <p>", adWriteLine
    tmpFile.WriteText " * 使用する定数を定義する", adWriteLine
    tmpFile.WriteText " * </p>", adWriteLine
    tmpFile.WriteText " */", adWriteLine
    tmpFile.WriteText "public class " & Range("B1").Value & " {", adWriteLine
    ' 開始行を設定
    outRow = 入力開始行
    ' 最終行まで繰り返す
    Do Until outRow > maxRow
        tmpFile.WriteText vbTab & "/**", adWriteLine
        'コメントの出力 開始
        tmpFile.WriteText vbTab & " * " & Cells(outRow, 区分名列).Value & "の定数です。", adWriteLine
        tmpFile.WriteText vbTab & " */", adWriteLine
        'コメントの出力 終了
        If Cells(outRow, 配列列).Value <> "" Then
            wStr = "public static final " & Cells(outRow, 型列).Value _
                    & " C_" & Cells(outRow, 区分名列) & "_" _
                    & Cells(outRow, 名称列).Value & " = {"
            tmpFile.WriteText vbTab & wStr
            cnt = LenB(StrConv(wStr, vbFromUnicode)) / 4
            If (LenB(wStr) Mod 4) > 0 Then
                cnt = cnt + 1
            End If
            wStr = ""
            For k = 1 To cnt
                wStr = wStr & vbTab
            Next k
            If Cells(outRow, 配列列).Value = "○" Then
                配列値行番号 = Split(Cells(outRow, 配列値行番号列).Value, ",", , vbTextCompare)
                i = UBound(配列値行番号)
                j = 0
                For Each 行番号 In 配列値行番号
                    If j > 0 Then
                        tmpFile.WriteText wStr
                    End If
                    tmpFile.WriteText "C_"
                    tmpFile.WriteText Cells(Int(行番号), 区分名列).Value
                    tmpFile.WriteText "_"
                    tmpFile.WriteText Cells(Int(行番号), 名称列).Value
                    If j < i Then
                        tmpFile.WriteText ", ", adWriteLine
                    End If
                    j = j + 1
                Next
            ElseIf Cells(outRow, 配列列).Value = "◎" Then
                配列値直接入力 = Split(Cells(outRow, 配列値直接入力列).Value, ",", , vbTextCompare)
                i = UBound(配列値直接入力)
                j = 0
                For Each 直接入力 In 配列値直接入力
                    If j > 0 Then
                        tmpFile.WriteText wStr
                    End If
                    If Cells(outRow, 囲む列).Value <> "" Then
                        tmpFile.WriteText """"
                    End If
                    tmpFile.WriteText 直接入力
                    If Cells(outRow, 囲む列).Value <> "" Then
                        tmpFile.WriteText """"
                    End If
                    If j < i Then
                        tmpFile.WriteText ", ", adWriteLine
                    End If
                    j = j + 1
                Next
            End If
            tmpFile.WriteText "};", adWriteLine
            tmpFile.WriteText "", adWriteLine
        Else
            tmpFile.WriteText vbTab & "public static final "
            tmpFile.WriteText Cells(outRow, 型列).Value
            tmpFile.WriteText " C_"
            tmpFile.WriteText Cells(outRow, 区分名列)
            tmpFile.WriteText "_"
            tmpFile.WriteText Cells(outRow, 名称列).Value
            tmpFile.WriteText " = "
            If Cells(outRow, 型列).Value = "String" Then
                tmpFile.WriteText """"
            End If
            wStr = Cells(outRow, 値列).Value
            wStr = Replace(wStr, "半角空白", " ", , , vbTextCompare)
            wStr = Replace(wStr, """", "", , , vbTextCompare)
            tmpFile.WriteText wStr
            If Cells(outRow, 型列).Value = "String" Then
                tmpFile.WriteText """"
            End If
            tmpFile.WriteText ";", adWriteLine
            tmpFile.WriteText "", adWriteLine
        End If        ' 行を加算
        outRow = outRow + 1
    Loop
    tmpFile.WriteText "", adWriteLine
    tmpFile.WriteText vbTab & "/**", adWriteLine
    tmpFile.WriteText vbTab & " * コンストラクタ", adWriteLine
    tmpFile.WriteText vbTab & " */", adWriteLine
    tmpFile.WriteText vbTab & "private " & Range("B1").Value & "() {", adWriteLine
    tmpFile.WriteText vbTab, adWriteLine
    tmpFile.WriteText vbTab & "}", adWriteLine
    tmpFile.WriteText "}", adWriteLine
    'ファイル名設定
    tmpFileName = ThisWorkbook.Path & "\tmp" & Range("B1").Value & ".java"
    fileName = ThisWorkbook.Path & "\" & Range("B1").Value & ".java"
    '一時ファイルに書き込み
    tmpFile.SaveToFile tmpFileName, adSaveCreateOverWrite
    '一時ファイルをクローズ
    tmpFile.Close
    Set tmpFile = Nothing
   
    'ここからBOM除去処理
    '一時ファイルの4バイト目から読み込む
    Set readFile = CreateObject("ADODB.Stream")
    readFile.Open
    readFile.Type = adTypeBinary
    readFile.LoadFromFile (tmpFileName)
    readFile.Position = 3
   
    '出力ファイルをオープン
    Set writeFile = CreateObject("ADODB.Stream")
    writeFile.Open
    writeFile.Type = adTypeBinary
    '読み込んだデータをそのままファイルに出力する(4バイト目以降を出力)
    writeFile.Write (readFile.Read(adReadAll))
    writeFile.SaveToFile fileName, adSaveCreateOverWrite
       
    'ファイルをクローズ
    writeFile.Close
    Set writeFile = Nothing
    readFile.Close
    Set readFile = Nothing
   
    '一時ファイル削除
    Kill tmpFileName
   
End Sub

2011年5月20日金曜日

Eclipse SVN ユーザ情報変更編

@ECHO OFF
ECHO Eclipseのユーザ切り替えバッチ
REM 初期設定
SET DASDir="C:\Documents and Settings\%USERNAME%"
SET SVNUsr="C:\Documents and Settings\%USERNAME%\Application Data\Subversion\auth\svn.simple\"
SET 標準="%DASDir%\SVN標準"
SET 管理="%DASDir%\SVN管理"
SET 複写元=""
:START
COLOR 0a
SET /P INPUT=使用するユーザを指定 [1:標準ユーザ, 2:管理ユーザ, 9:終了] :
IF %INPUT% EQU 1 (
    SET 複写元=%標準%
    GOTO DOCOPY
)
IF %INPUT% EQU 2 (
    SET 複写元=%管理%
    GOTO DOCOPY
)
IF %INPUT% EQU 9 (
    GOTO END
)
COLOR 0C
ECHO 入力した値が正しくありません。
ECHO 再度入力してください。
PAUSE
GOTO START

:DOCOPY
CD %複写元%
COPY ファイル名 %SVNUsr%
PAUSE
EXIT
:END
PAUSE

2011年5月19日木曜日

Excel VBA ファイル出力


参照設定でMicrosoft Scripting Runtimeを設定した場合

Dim FSO As New FileSystemObject
Dim TS As TextStream
 
Set TS = FSO.CreateTextFile("c:\a.txt")
TS.WriteLine "文字を出力"
TS.Close
Set TS = Nothing
Set FSO = Nothing



参照設定をしない場合

Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
 
Set TS = FSO.CreateTextFile("c:\a2.txt")
TS.WriteLine "文字を出力"
TS.Close
Set TS = Nothing
Set FSO = Nothing

Excel VBA Java用定数クラス作成マクロ編

<エクセルのレイアウト>

3行目
B列 区分名
C列 値
D列 名称
E列 型(String等)
F列 配列 ○:配列値行番号使用、◎:配列値直接入力使用 
G列 配列値行番号
H列 配列値直接入力


4行目以降は値

<マクロの内容>


Option Explicit
Private Const 入力開始行 = 4
Private Const 区分名列 = 2
Private Const 値列 = 3
Private Const 名称列 = 4
Private Const 型列 = 5
Private Const 配列列 = 6
Private Const 配列値行番号列 = 7
Private Const 配列値直接入力列 = 8
Private Const 囲む列 = 9
Private Sub クラス作成_Click()
    Dim maxRow As Integer           ' 最終行番号
    Dim outRow As Integer           ' 出力行
    Dim i, j, k, cnt As Integer
    Dim wStr As String              ' ワーク文字
    Dim TS As TextStream            ' TextStream
    Dim FSO As New FileSystemObject ' FileSystemObject
    Dim 配列値行番号() As String
    Dim 配列値直接入力() As String
    Dim 行番号, 直接入力 As Variant
    '最終行取得
    maxRow = ActiveSheet.Range("B65536").End(xlUp).Row
    '入力開始位置確認
    If maxRow < 入力開始行 Then
        MsgBox "値が入力されていません。"
        Exit Sub
    End If
    Set TS = FSO.CreateTextFile( _
        fileName:=ThisWorkbook.Path & "\" & Range("B1").Value & ".java", _
        Overwrite:=True)
   
    TS.WriteLine "/******************************************************************"
    TS.WriteLine " * モジュール名"
    TS.WriteLine " * " & Range("B1").Value & ".java"
    TS.WriteLine " *"
    TS.WriteLine " * 変更履歴"
    TS.WriteLine " *    日付          変更者    変更概要"
    TS.WriteLine " *  YYYY/MM/DD    氏  名      新規作成"
    TS.WriteLine " ******************************************************************"
    TS.WriteLine " */"
    TS.WriteLine
    TS.WriteLine "package jp.co.xxx.common.constant;"
    TS.WriteLine
    TS.WriteLine "/**"
    TS.WriteLine " * 共通定数"
    TS.WriteLine " * <p>"
    TS.WriteLine " * 使用する定数を定義する"
    TS.WriteLine " * </p>"
    TS.WriteLine " */"
    TS.WriteLine "public class " & Range("B1").Value & " {"

    ' 開始行を設定
    outRow = 入力開始行
    ' 最終行まで繰り返す
    Do Until outRow > maxRow
        TS.WriteLine vbTab & "/**"
        'コメントの出力 開始
        TS.WriteLine vbTab & " * " & Cells(outRow, 区分名列).Value & "の" & Replace(Cells(outRow, 名称列).Value, "J_", "", , , vbTextCompare) & "の定数です。"
        TS.WriteLine vbTab & " */"
        'コメントの出力 終了
        If Cells(outRow, 配列列).Value <> "" Then
            wStr = "public static final " & Cells(outRow, 型列).Value _
                    & " C_" & Cells(outRow, 区分名列) & "_" _
                    & Cells(outRow, 名称列).Value & " = {"
            TS.Write vbTab & wStr
            cnt = LenB(StrConv(wStr, vbFromUnicode)) / 4
            If (LenB(wStr) Mod 4) > 0 Then
                cnt = cnt + 1
            End If
            wStr = ""
            For k = 1 To cnt
                wStr = wStr & vbTab
            Next k
            If Cells(outRow, 配列列).Value = "○" Then
                配列値行番号 = Split(Cells(outRow, 配列値行番号列).Value, ",", , vbTextCompare)
                i = UBound(配列値行番号)
                j = 0
                For Each 行番号 In 配列値行番号
                    If j > 0 Then
                        TS.Write wStr
                    End If
                    TS.Write "C_"
                    TS.Write Cells(Int(行番号), 区分名列).Value
                    TS.Write "_"
                    TS.Write Cells(Int(行番号), 名称列).Value
                    If j < i Then
                        TS.WriteLine ", "
                    End If
                    j = j + 1
                Next
            ElseIf Cells(outRow, 配列列).Value = "◎" Then
                配列値直接入力 = Split(Cells(outRow, 配列値直接入力列).Value, ",", , vbTextCompare)
                i = UBound(配列値直接入力)
                j = 0
                For Each 直接入力 In 配列値直接入力
                    If j > 0 Then
                        TS.Write wStr
                    End If
                    If Cells(outRow, 囲む列).Value <> "" Then
                        TS.Write """"
                    End If
                    TS.Write 直接入力
                    If Cells(outRow, 囲む列).Value <> "" Then
                        TS.Write """"
                    End If
                    If j < i Then
                        TS.WriteLine ", "
                    End If
                    j = j + 1
                Next
            End If
            TS.WriteLine "};"
            TS.WriteLine
        Else
            TS.Write vbTab & "public static final "
            TS.Write Cells(outRow, 型列).Value
            TS.Write " C_"
            TS.Write Cells(outRow, 区分名列)
            TS.Write "_"
            TS.Write Cells(outRow, 名称列).Value
            TS.Write " = "
            If Cells(outRow, 型列).Value = "String" Then
                TS.Write """"
            End If
            wStr = Cells(outRow, 値列).Value
            wStr = Replace(wStr, "半角空白", " ", , , vbTextCompare)
            wStr = Replace(wStr, """", "", , , vbTextCompare)
            TS.Write wStr
            If Cells(outRow, 型列).Value = "String" Then
                TS.Write """"
            End If
            TS.WriteLine ";"
            TS.WriteLine
        End If
        ' 行を加算
        outRow = outRow + 1
    Loop
    TS.WriteLine
    TS.WriteLine vbTab & "/**"
    TS.WriteLine vbTab & " * コンストラクタ"
    TS.WriteLine vbTab & " */"
    TS.WriteLine vbTab & "private " & Range("B1").Value & "() {"
    TS.WriteLine vbTab
    TS.WriteLine vbTab & "}"
    TS.WriteLine "}"
    ' 指定ファイルをCLOSE
    TS.Close
    Set TS = Nothing
    Set FSO = Nothing
End Sub

2011年5月18日水曜日

teratermマクロ ログファイル出力編

; 日時の取得とファイル名に使用出来るように組み替え
getdate W_DATE
gettime W_TIME
strcopy W_DATE 1 4 nen
strcopy W_DATE 6 2 gatu
strcopy W_DATE 9 2 hi
strcopy W_TIME 1 2 nanji
strcopy W_TIME 4 2 nanfun
strcopy W_TIME 7 2 nanbyou

filename = 'ファイルパス'

strconcat filename nen
strconcat filename gatu
strconcat filename hi
strconcat filename '_'
strconcat filename nanji
strconcat filename nanfun
strconcat filename nanbyou
strconcat filename '.log'

logopen filename 0 1

2011年5月17日火曜日

Excel VBA バックアップ作成方法

システムタイムスタンプをファイル名に付けてバックアップ

backUpName = Replace(ThisWorkbook.FullName, _
                ".xls", _
                "_" & Format(Now, "yyyymmddhhmmss") & ".xls")

ActiveWorkbook.SaveCopyAs backUpName

2011年5月16日月曜日

teratermマクロ 自動ログイン編

最善の方法じゃないと思うけど。
マクロにユーザIDとパスワード直書きだからなぁ…。

; ユーザID
username = 'XXXXXX'
; パスワード
password ='******'

; サーバのIP
hostname = 999.999.999.999'
; パラメータ設定
msg = hostname
strconcat msg ':22 /ssh /2 /auth=password /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg password

; ログイン
connect msg

2011年5月15日日曜日

Windows cmdでファイル作成

たまーにcmdでファイルを作成したいときがある。 そんなときに使います。 copy con test.txt[enter] 出力したい内容を入力。[enter] 改行も可能。 [crtl]+[z][enter] ※[]はキー

2011年5月14日土曜日

Excel VBA A1セルの値取得

アクティブセルの値を取得
ActiveCell.Value


セルの値を取得

ActiveSheet.Range("A1").Value
ActiveSheet.Cells(1,1).Value


アクティブセルの表示値を取得
ActiveCell.Text

セルの表示値を取得
ActiveSheet.Range ("B1").Text
ActiveSheet.Cells(1,2).Text



2011年5月13日金曜日

Excel VBA 気になったこと

ThisWorkbook と ActiveWorkbook の違い

ThisWorkbookはマクロ(処理)を記述したブック
AcitveWorkbookは現在アクティブになっているブック

状況によって、使い分けが必要なのか。

2011年5月12日木曜日

Excel シート名の変更


シート名を指定して変更する場合
ThisWorkbook.Sheets("Sheet1").Name = "変更"

シート番号を指定して変更する場合
ThisWorkbook.Sheets(1).Name = "変更"


2011年5月11日水曜日

JAVA JARの中身確認

Jarに含まれている内容を確認したかったのでちょっと調べてみた。

以外に簡単にできるらいしい。

Jarに含まれているパッケージとクラスの確認
jar tf test.jar

 フォルダ内のJarを一度に確認
For /F %%A in (dir /b *.jar) DO jar tf %%A

2011年5月9日月曜日