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?

More than 5 years have passed since last update.

【VBA】既定のアプリ(秀丸)でtxtファイルを開く

Posted at
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub TestMain()
    Dim strFile As String
    Dim WSH As Object
    Set WSH = CreateObject("WScript.Shell")
        
    'フyァイルのフルパスを指定
    strFolda = Range("Q2")
    strFile = Cells(2, 16)
    strName = strFolda + "\" + strFile

    If Dir(strName) = "" Then
        MsgBox "ファイルが存在しません。"
        Exit Sub
    End If
    
    WSH.Run strName, 1
    
    Call key
End Sub
Sub key()
    Sleep 500
    SendKeys "{ENTER}", True
    
    Sleep 500
    SendKeys "y", True
End Sub

■参考サイト
< Run >
https://win.just4fun.biz/?WSH/%E5%A4%96%E9%83%A8%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%92%E5%AE%9F%E8%A1%8C%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%E3%83%BBRun%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89

< キー操作 >
https://excwlvba.blogspot.com/2013/05/sendkeys.html

< 他アプリ操作 >
https://officeforest.org/wp/2018/04/22/vba%E3%81%A7%E4%BB%96%E3%81%AE%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B/

< アプリウィンドウアクティブ化 >
https://docs.microsoft.com/ja-jp/office/vba/language/reference/user-interface-help/appactivate-statement

< Shell >
http://officetanaka.net/excel/vba/function/Shell.htm


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?