excel vba - How to open and display text file at specific line from VBA -


i have vba userform handy open associated text file in textpad. can achieve following:

call shell("c:\program files\textpad 5\textpad.exe " & "c:\testfile.txt", vbnormalfocus) 

however, i'd have text file displayed @ specific line number. there way pass line number argument shell call? i'm @ loss here.

you can accomplish using wscript.shell.sendkeys trigger goto line shortcut within textpad (ctrl-g)

dim wshshell set wshshell = createobject("wscript.shell")  call shell("c:\program files\textpad 5\textpad.exe " & "c:\testfile.txt", vbnormalfocus) application.wait (10) wshshell.sendkeys "^g"      'ctrl-g application.wait (10) wshshell.sendkeys "15"      'desired line number application.wait (10) wshshell.sendkeys "{enter}" 'enter 

you might have mess wait lines add or remove delays between commands, tested within vba module in excel , worked.

i aware sendkeys can called directly vba, when tried use that, seems bound vba editor window.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -