2016-09-08 58 views
3

我希望文件保存爲使用用戶在開始處輸入的變量STYLE。AHK COM保存時通過文件路徑傳遞變量

我還需要幫助將數據發送到具有可變數量副本的打印機。

從這裏就是我需要幫助:

ComObjActive("Word.Application").ActiveDocument.SaveAs("L:\10. 2016\TKT Issued\"%Style%") 

請看看什麼我已經有下面的代碼。

#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. 

F12:: 
Gui, Add, Text,, Please enter Style: 
Gui, Add, Edit, vStyle 
Gui, Add, Text,, Please enter Price: 
Gui, Add, Edit, vPrice 
Gui, Add, Text,, Please enter Docket Number: 
Gui, Add, Edit, vDocket 
Gui, Add, Text,, Please enter Page Quantity: 
Gui, Add, Edit, vPages 
Gui, Add, Button, default, OK 
Gui, Show,, Cutting Ticket Producer 
return 


GuiClose: 
ButtonOK: 
Gui, Submit 
MsgBox You entered Style: %Style%, Price: %Price%, Docket Number: %Docket% and%Pages% Pages. Data will be sent to printer. 


MSWordMultiReplace("STYLE",Style, "PRICE", Price, "DKT", Docket)  

MSWordMultiReplace(params*) { ; by Learning one 

    oWord := ComObjCreate("Word.Application") 
    a:="L:\10. 2016\TKT Issued\TEMPLATE.doc" 
    oWord.Documents.Open(a) 
    oWord.Selection.Find.ClearFormatting 
    oWord.Selection.Find.Replacement.ClearFormatting  
    For k,v in Params 
    { 
     c++ 
     if (c = 1) 
     { 
      st := v 
      continue 
     } 
     rt := v, c := 0 
     oWord.Selection.Find.Execute(st, 0, 0, 0, 0, 0, 1, 1, 0, rt, 2) 
    } 
ComObjActive("Word.Application").ActiveDocument.SaveAs("L:\10. 2016\TKT Issued\"%Style%") 


    ExitApp 
} 
Reload 

回答

0

嘗試:

#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. 

F12:: 
Gui, Add, Text,, Please enter Style: 
Gui, Add, Edit, vStyle 
Gui, Add, Text,, Please enter Price: 
Gui, Add, Edit, vPrice 
Gui, Add, Text,, Please enter Docket Number: 
Gui, Add, Edit, vDocket 
Gui, Add, Text,, Please enter Page Quantity: 
Gui, Add, Edit, vPages 
Gui, Add, Button, default, OK 
Gui, Show,, Cutting Ticket Producer 
return 


GuiClose: 
ButtonOK: 
Gui, Submit 
MsgBox You entered Style: %Style%, Price: %Price%, Docket Number: %Docket% and%Pages% Pages. Data will be sent to printer. 


MSWordMultiReplace("STYLE",Style, "PRICE", Price, "DKT", Docket)  

MSWordMultiReplace(params*) { ; by Learning one 

    oWord := ComObjCreate("Word.Application") 
    a:="L:\10. 2016\TKT Issued\TEMPLATE.doc" 
    oWord.Documents.Open(a) 
    oWord.Selection.Find.ClearFormatting 
    oWord.Selection.Find.Replacement.ClearFormatting  
    For k,v in Params 
    { 
     c++ 
     if (c = 1) 
     { 
      st := v 
      continue 
     } 
     if (k == 2) 
      Style := v 

     rt := v, c := 0 
     oWord.Selection.Find.Execute(st, 0, 0, 0, 0, 0, 1, 1, 0, rt, 2) 
    } 
    oWord.ActiveDocument.SaveAs("L:\10. 2016\TKT Issued\" Style) 


    ExitApp 
} 
Reload 
+0

這沒有奏效。 –

+0

由於某種原因,我忽略了可變參數函數,編輯了答案,讓我知道這是否有幫助。 – errorseven

+0

非常感謝您的幫助。你能幫助打印部分嗎? –

0

你不能直接訪問Style變量。你必須把它作爲你傳遞的第二個參數。請參見下面的代碼,

For k,v in params 
{ 
    if (k = 2) 
    { 
     fileloc = L:\10. 2016\TKT Issued\%v% 
     ComObjActive("Word.Application").ActiveDocument.SaveAs(fileloc) 
    } 
} 

這個工作對我來說

+0

謝謝,這個作品。 你能在印刷品上建議我嗎? –

+0

嗨它保存與變量名稱的文件,因爲我想,但它是保存文件進行更改之前? –