【问题标题】:AHK COM Passing Variable through File Path when savingAHK COM在保存时通过文件路径传递变量
【发布时间】:2017-01-16 11:58:32
【问题描述】:

我希望文件保存为使用用户在开始时输入的变量 STYLE。

我还需要帮助将数据发送到具有可变份数的打印机。

从这里开始我需要帮助:

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

【问题讨论】:

    标签: com autohotkey


    【解决方案1】:

    试试:

    #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
    

    【讨论】:

    • 由于某种原因,我忽略了可变参数函数,编辑了答案,如果有帮助,请告诉我。
    • 非常感谢您的帮助。你能帮忙打印部分吗?
    • 不客气。我建议您单独询问有关打印多个文档的问题,并确保包含您尝试过的任何代码。
    【解决方案2】:

    您不能直接访问Style 变量。您必须将其作为您传递的第二个参数。看下面的代码,

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

    这对我有用

    【讨论】:

    • 谢谢,这行得通。你能就印刷部分给我建议吗?
    • 您好,它使用我想要的变量名保存文件,但是在进行更改之前它会保存文件?
    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多