Search code examples
comautohotkey

AHK COM Passing Variable through File Path when saving


I would like the file to save as using the variable STYLE which the user enters at the beginning.

I also need help sending the data to a printer with variable amount of copies.

From here on is where I need help:

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

Please look at the below code for what I already have.

#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

Solution

  • Try:

    #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