word文檔批量合併工具

用於批量合併word文檔

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance Force
FileInstall ,D:\2 IE天使\ICO圖標製作\ICO圖標文件2\ICO2\s023.ico,c:\3.ico,1
If fileExist("C:\3.ico")
	Menu, Tray, Icon, c:\3.ico, , 1  ;顯示圖標
try 
{
	wd:=ComObjActive("word.Application")
}catch e{  ;用於捕獲錯誤,未啓動word就拋出!!!
	MsgBox 當前未啓動word,請先打開word,注意不是WPS!!!
	return
}
SetWorkingDir %A_ScriptDir%
Gui Font, s13
Gui Add, Text, x150 y1 w538 h50 +0x200, word文檔合併工具  ;後面可修飾字體顏色,字號等;
Gui, Add, Checkbox, x60 y175 w200 h20  v子文件夾 checked, 合併子文件夾中的文檔
Gui, Add, Checkbox, x300 y175 w200 h20  v擴展名, 顯示擴展名
Gui Add, Button, x144 y205 w160 h70  g開始合併, 開始合併
Gui Font
Gui Font, s14
Gui Add, Text, x28 y44 w538 h50 +0x200, 將要合併的文件夾拖入,或者定位文件夾(必須先打開word)
Gui Font
Gui Add, Edit, x32 y112 w366 h49 vEdit1
Gui Add, Button, x407 y118 w75 h47 g定位, 定位
Gui Show, w550 h314, Word文檔合併工具
Return
;autogui如何反相生成gui?
GuiEscape:
GuiClose:
    ExitApp

; End of the GUI section
開始合併:
Gui, Submit

doc0:=wd.documents.add
Loop  ,%Edit1%\*.doc*, 0, %子文件夾% ;第三個參數:0-僅文件;1-文件+文件夾;2-僅文件夾,但是若是前面僅僅給出個母文件夾的話,可以但限制了具體文件後綴的話2就無效了;最後一個爲1時爲遞歸;
{
	st:=doc0.range.end-1
	if(擴展名=1)
		doc0.range.InsertAfter(A_LoopFileName "`r`n")  ;帶擴展名
	else
		doc0.range.InsertAfter(RegExReplace(A_LoopFileName,"`ami)\..*$") "`r`n")  ;不帶擴展名
	
	  doc0.Range(st,doc0.range.end-1).Style := ("標題 2")
      doc0.Range(st,doc0.range.end-1).Font.Color:=255 ;0x0000FF ;RGB(255, 0, 0)
	doc0.range(doc0.range.end-1,doc0.range.end-1).Insertfile(A_LoopFileLongPath) ;插入文件
}
WinActivate, % doc0.name  ;激活文檔
MsgBox  "已完成!!!" 
;~ doc0.saveas "c:\tesd.doc"
return

定位:
FileSelectFolder,fod,,3,文件夾選擇 ;FileSelectFolder, OutputVar, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}  ; 我的電腦.
if(fod="")
	return
GuiControl,, Edit1, %fod%
return


GuiDropFiles:  ; 對拖放提供支持.經典代碼★★★★★★★★★★★★※※※※※※
SelectedFileName := A_GuiEvent
;獲取鼠標下面的控件★★★★★★★★★★★★★★★★★★★★★
MouseGetPos, , , id, control
;~ WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
;~ ToolTip, ahk_id %id%`nahk_class %class%`n%title%`nControl: %control%
if (control="Edit1")
{
	GuiControl,, Edit1, %SelectedFileName%  ; 在控件中顯示文本.
}
if (control="Edit2")
{
	GuiControl,, Edit2, %SelectedFileName%  ; 在控件中顯示文本.
}
return


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章