I'm trying to create a new word file with a predefined name in a specific folder. I used the following script but fail to open the file. Could anyone help deal with this? Thank you a million.
Ryan Huang
Code: Select all
#!w::
; create new word file in current window focus
#IfWinActive ahk_class CabinetWClass
>!w:: ;explorer - create new word file and focus/select it
#IfWinActive ahk_class ExploreWClass
>!w:: ;explorer - create new word file and focus/select it
;note: similar to: right-click, New, Word Document
vNameNoExt := "Comments"
vDotExt := ".docx"
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
if (oWin.HWND = hWnd)
{
vDir := RTrim(oWin.Document.Folder.Self.Path, "\")
;if !DirExist(vDir)
if !InStr(FileExist(vDir), "D")
{
oWin := ""
return
}
Loop
{
vSfx := (A_Index=1) ? "" : " (" A_Index ")"
vName := vNameNoExt vSfx vDotExt
vPath := vDir "\" vName
if !FileExist(vPath)
break
}
;create a blank word file (ANSI/UTF-8/UTF-16)
;FileAppend,, % "*" vPath
FileAppend,, % "*" vPath, UTF-8
;FileAppend,, % "*" vPath, UTF-16
;SVSI_FOCUSED := 0x10 ;SVSI_ENSUREVISIBLE := 0x8
;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
Loop 30
{
if !(oWin.Document.Folder.Items.Item(vName).path = "")
{
oWin.Document.SelectItem(vPath, 0x1F)
break
}
Sleep, 100
}
break
}
}
oWin := ""
return
#IfWinActive