LoginSignup
5
5

More than 5 years have passed since last update.

エクセルVBAでいろいろ

Posted at

ファイルを開くダイアログを開いて、選択したファイルのファイル名を変数に入れる。

    Dim ファイル As String

    ChDir ThisWorkbook.Path & "\"
    ファイル = Application.GetOpenFilename("CSVファイル, *.csv")

CSVファイルを開いて一行ずつ読み込んでカンマで分割して配列に入れる。

Dim answer(100, 5) As String
Dim str As String
Dim tmp As Variant
Dim cnt As Long

Open ファイル For Input As #1
    Do Until EOF(1) = True
        Line Input #1, str
        tmp = Split(str, ",")
        cnt = cnt + 1
        answer(cnt, 1) = tmp(0)
        answer(cnt, 2) = tmp(1)
        answer(cnt, 3) = tmp(2)
        answer(cnt, 4) = tmp(3)
        answer(cnt, 5) = tmp(4)
    Loop
Close #1

印刷範囲を指定する。

ActiveSheet.PageSetup.PrintArea = "A1:J55"

正規表現で文字列置換

Set reg = CreateObject("VBScript.RegExp")
pat = "「.+」"
With reg
   .Pattern = pat
   .IgnoreCase = True
   .Global = True
End With

result = reg.Replace("「なにか?」", "")

デバッグ用の出力。

Debug.Print "result=" & Result
5
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5