0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

改行を20個入力した状態でメモ帳を開くVBScript

Last updated at Posted at 2024-08-12

DateModule.vbs
FsoModule.vbs
WShllModule.vbs

※Include用のモジュールファイルは、スクリプトを保存するフォルダに「Module」というフォルダを作ってそこに格納しておく。

MemoEOF.vbs
Option Explicit

Include "DateModule"
Include "FsoModule"
Include "WShllModule"

Dim folderPath, fileName, filePath

folderPath = MakeFolder(GetBuildPath(Array(DesktopPath, "TXT", "memo")))
fileName = "memo" & DateFormat(Now, "[yyyy-mm-dd]hhnnss") & ".txt"

With Fso
    filePath = .BuildPath(folderPath, fileName)
    With .OpenTextFile(filePath, 8, True)
        .Write StringN(20, vbCrLf)
        .Write "[EOF]"
        .Close
    End With
End With

OpenFolder filePath
wShll.run "notepad " & filePath
'// 与えられた文字を指定回数つなげた文字列を返す
'// String関数で改行(vbCrLf)をつなげると vbCr だけになるため

Function StringN(ByVal n, ByVal str)

    Dim i, strN

    For i = 1 To n
        strN = strN & str
    Next

    StringN = strN

End Function
'// 外部関数ライブラリ(VBSファイル)の読み込み

Function Include(ByVal mod_name)

    Dim modFolderPath

    With CreateObject("Scripting.FileSystemObject")
        modFolderPath = .BuildPath(.GetFolder(".").Path, "Module")
        With .OpenTextFile(.BuildPath(modFolderPath, mod_name & ".vbs"))
            ExecuteGlobal .ReadAll
            .Close
        End With
    End With

End Function

<参考サイト>
【vbCrLfの注意点】String関数で繰り返してはいけない(VBA)

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?