0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VBA テキストファイルを作成し、開いてフォーカスする

Last updated at Posted at 2020-05-23

貼り付け実行で行ける。

参考URL:
https://excel-ubara.com/excelvba1/EXCELVBA422.html

 Function fncMakeAndOpenFile()
 
    Dim fso As Object
    Dim ts As TextStream
    Dim strPathCur As String
    
    strPathCur = ThisWorkbook.path
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(strPathCur & "\Temp.txt", ForWriting, True) 
' 追記は「ForAppending」新規は「ForWriting」読み取りは「ForReading」

    ts.Write ("文字列")       ' 文字列の書き込み(複数行は書き込めない)
    ts.WriteLine ("改行付き") ' 最後に改行を付けて書き込み
    ts.WriteBlankLines (3)    ' 空行を指定の数だけ書き込み
    
    ts.Close ' ファイルを閉じる

    Shell "C:\Windows\System32\notepad.exe """ & strPathCur & "\Temp.txt""", vbNormalFocus
        
 End Function
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?