 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Should this be continued? |
| Yes |
|
93% |
[ 14 ] |
| No |
|
6% |
[ 1 ] |
|
| Total Votes : 15 |
|
| Author |
Message |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Wed Mar 10, 2010 5:16 pm Post subject: |
|
|
---------------------------
FileRead_VOICEPLS.ahk
---------------------------
Error: Call to nonexistent function.
Specifically: Word_Open()
Line#
001: FileRead,request,C:\Users\%username%\Hotkeys\customer name.txt
002: COM_CoInitialize()
---> 003: Word_Open()
004: Bold := True
005: FontSize := 10
006: Word_InsertText("testing")
007: COM_CoUnInitialize()
008: ExitApp
008: Exit
008: {
The program will exit.
---------------------------
OK
--------------------------- _________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Wed Mar 10, 2010 5:25 pm Post subject: |
|
|
Did you #Include the script in the first post that contains that function, or, did you copy the function from that script to the script you're using? _________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Wed Mar 10, 2010 5:27 pm Post subject: |
|
|
I copied I didn't see #Include in there. I must have missed it? Where do you suggest I put it? _________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Wed Mar 10, 2010 5:31 pm Post subject: |
|
|
Try this and see if it works:
| Code: | COM_CoInitialize()
Word_Open()
COM_CoUninitialize()
return
Word_Open() {
Word := Word_Attach("N")
wDoc := COM_Invoke(Word, "Documents")
COM_Invoke(wDoc,"Add")
; COM_Invoke(wDoc,"Select")
COM_Release(wDoc), COM_Release(Word)
return
}
Word_Attach(sInstance="A") {
SetWinDelay, 0
oWord := (sInstance="N") ? COM_CreateObject("Word.Application")
: COM_GetActiveObject("Word.Application")
COM_Invoke(oWord,"Visible",True)
COM_Invoke(oWord,"Activate")
return oWord
} |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Thu Mar 11, 2010 7:24 pm Post subject: |
|
|
I copied and pasted your code into a brand new .ahk file. I receive this error...
| Quote: | ---------------------------
word.ahk
---------------------------
Error: Call to nonexistent function.
Specifically: Word_Attach("N")
Line#
001: COM_CoInitialize()
002: Word_Open()
003: COM_CoUninitialize()
004: Return
006: {
---> 008: Word := Word_Attach("N")
009: wDoc := COM_Invoke(Word, "Documents")
010: COM_Invoke(wDoc,"Add")
012: COM_Release(wDoc), COM_Release(Word)
013: Return
014: }
014: Exit
008: {
The program will exit.
---------------------------
OK
--------------------------- |
_________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Thu Mar 11, 2010 7:31 pm Post subject: |
|
|
I don't think you copied the entire code from my post, if you scroll down in the posted code you'll see that it contains the Word_Attach function. _________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Thu Mar 11, 2010 7:34 pm Post subject: |
|
|
Ahhh. This be true. Sorry 'bout that. Now, where can I put in the paramaters for bold/italic/underline/size etc.? And, where does the text go? Or should I just use "Send"? _________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Thu Mar 11, 2010 9:02 pm Post subject: |
|
|
Since the other part now works we can add back in the other functions to set the text. Copy the whole script below and try to run it, I re-wrote some of the functions a dab to attempt to optimize functionality:
| Code: | test:="to see if it's working!!!"
COM_CoInitialize()
Word_Open()
FontSize:=10
Bold:=True
Word_InsertText("This is just a test ")
Word_SetCurrentFont("",FontSize,Bold)
Word_InsertText(test)
COM_CoUninitialize()
return
Word_Open() {
wd := Word_Attach("N")
COM_Invoke(wd, "Documents.Add")
; COM_Invoke(wDoc,"Add")
; COM_Invoke(wDoc,"Select")
COM_Release(wd)
return
}
Word_Attach(sInstance="A") {
SetWinDelay, 0
wd := (sInstance="N") ? COM_CreateObject("Word.Application")
: COM_GetActiveObject("Word.Application")
COM_Invoke(wd,"Visible=",True)
COM_Invoke(wd,"Activate")
return wd
}
Word_InsertText(Text) {
wd := Word_Attach("A") ; Attach to Active Window
wd := COM_Invoke(wd,"Selection") ; Get Insertion Point or Selected text
COM_Invoke(wd,"TypeText", Text) ; Put the text there
COM_Release(wd)
return
}
Word_SetCurrentFont(Name="Times New Roman",Size="10",Bold=0,Italic=0,Caps=0) {
wd := Word_Attach("A") ; Attach to Active Window
wd := COM_Invoke(wd,"Selection.Font")
COM_Invoke(wd,"Name=", !Name ? "Times New Roman" : Name)
COM_Invoke(wd,"Size=", !Size ? 10 : Size)
COM_Invoke(wd,"Bold=", !Bold ? 0 : 1)
COM_Invoke(wd,"Italic=", !Italic ? 0 : 1)
COM_Invoke(wd,"AllCaps=", !Caps ? 0 : 1)
COM_Release(wd)
return
} |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Thu Mar 11, 2010 9:05 pm Post subject: |
|
|
Workin' perfect. Thank you. _________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Thu Mar 11, 2010 11:16 pm Post subject: |
|
|
I decided to go ahead and re-write some of the functions in this thread to take advantage of the object-oriented syntax offered by AHK_L and COM_L. Some of them have been tested but some have not, please let me know if you receive a failure while using any of them so I can make sure they are written correctly. Also any suggestions for optimization are also welcome:
MS Word:
| Code: | ; 03-11-2010 - The following functions originally created by ahklerner have been re-written
; by sinkfaze for compatability with AHK_L's object-oriented syntax.
; REQUIRES AHK_L and COM_L Standard Library
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:15
; Function Name: Word_InsertText()
;
; Insert text into the current document at the insertion point or overwriting selected area
;
; Syntax:
; Word_InsertText(Text)
; Parameters:
; Text = the text string to insert into the document
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_InsertText(Text) {
wd := Word_Attach().Selection
wd.TypeText[Text]
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:16
; Function Name: Word_Open()
;
; Start a new instance of word
;
; Syntax:
; Word_Open()
; Parameters:
; None
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Open() {
wd := Word_Attach("N") ; Attach to New Window
wd.Documents.Add()
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:17
; Function Name: Word_Close()
;
; Close all instances of word
; may prompt for save dialog.
;
; Syntax:
; Word_Close()
; Parameters:
; None
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Close() {
wd := Word_Attach()
wd.Quit()
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:18
; Function Name: Word_SaveAs()
;
; Syntax:
; Word_SaveAs(SaveFileName)
; Parameters:
; SaveFileName = The name to save the file as. Must be Full Path
; Return:
; Success =
; Failure =
; **************************************************************************
Word_SaveAs(SaveFileName) {
wdFormatDocument := 0
wd := Word_Attach().ActiveDocument
wd.SaveAs[SaveFileName, wdFormatDocument]
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:18
; Function Name: Word_Save()
;
; Save the current file
;
; Syntax:
; Word_Save()
; Parameters:
; None
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Save() {
wd := Word_Attach().ActiveDocument
wd.Save()
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:19
; Function Name: Word_OpenDoc()
;
; Syntax:
; Word_OpenDoc(FileName)
; Parameters:
; FileName = The file name to open
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_OpenDoc(FileName) {
wd := Word_Attach("N").Documents
wd.Open[FileName]
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:19
; Function Name: Word_GetActiveTitle()
;
; Gets the title of the Active document
;
; Syntax:
; Word_GetActiveTitle()
; Parameters:
; None
; Return:
; Success = The title of the active document
; Failure = nothing
; **************************************************************************
Word_GetActiveTitle() {
wd := Word_Attach().ActiveDocument
Name := wd.Name
wd:= ""
return Name
}
;get document text
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:21
; Function Name: Word_GetText()
;
; Get the text of the Active Document
;
; Syntax:
; Word_GetText()
; Parameters:
; None
; Return:
; Success = The document text
; Failure = nothing
; **************************************************************************
Word_GetText() {
wd := Word_Attach().ActiveDocument.Range
Text := wd.Text
wd:= ""
return Text
}
;Get selected text
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:21
; Function Name: Word_GetSelection()
;
; Get the currently selected text in the active document
;
; Syntax:
; Word_GetSelection()
; Parameters:
; None
; Return:
; Success = the currently selected text
; Failure = nothing
; **************************************************************************
Word_GetSelection() {
wd := Word_Attach().Selection
Text := wd.Text
wd:= ""
return Text
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:22
; Function Name: Word_SetCurrentFont()
;
; Set the font of the selected text or the current font
;
; Syntax:
; Word_SetCurrentFont(sFontName="Times New Roman",sFontSize="10",bBold=0,bItalic=0,bCaps=0)
; Parameters:
; name="Times New Roman" = The name of the font to use
; sz="10" = The font size
; b=0 = True or False Bold
; i=0 = True or False Italic
; c=0 = True or False All Caps
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_SetCurrentFont(name="Times New Roman",sz="10",b=0,i=0,c=0) {
wd := Word_Attach().Selection.Font
wd.Name := !name ? "Times New Roman" : name]
wd.Size := !sz ? 10 : sz ; Font Size
wd.Bold := !b ? 0 : 1 ; Bold
wd.Italic := !i ? 0 : 1 ; Italic
wd.AllCaps := !c ? 0 : 1 ; Caps
wd:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:24
; Function Name: Word_Detach()
;
; com_release wrapper for consistency
;
; Syntax:
; Word_Detach(ObjWord)
; Parameters:
; ObjWord = Handle to already opened object
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Detach(ObjWord) {
ObjWord:= ""
return
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:26
; Function Name: Word_Attach()
;
; Gets the active Word Object or creates a new one
;
; Syntax:
; Word_Attach(sInstance="A")
; Parameters:
; sInstance="A" = Values:
; A - Active Object - Default
; N - New Object
; Return:
; Success = handle to a word object
; Failure = Nothing
; **************************************************************************
Word_Attach(sInstance="A") {
SetWinDelay, 0
wd := (sInstance="N") ? COM_CreateObject("Word.Application")
: COM_GetActiveObject("Word.Application")
wd.Visible := True
wd.Activate()
return wd
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:31
; Function Name: Word_ObjGetHwnd()
;
; Gets the hWnd for a given Word object
;
; Syntax:
; Word_ObjGetHwnd(hObj)
; Parameters:
; hObj = Handle to word object
; Return:
; Success = hWnd to hObj 's parent window
; Failure = nothing
; **************************************************************************
Word_ObjGetHwnd(hObj){
DetectHiddenWindows, On
SetTitleMatchMode, 2
; http://support.microsoft.com/kb/310744
; Generate a unique title
sCaption := "[" UUID() "]"
; set the title of the window
COM_Invoke(hObj,"Caption=",sCaption)
; get the current caption
sCaption := COM_Invoke(hObj,"Caption") ; Should not be necessary, may not be
if !hWnd := WinExist(sCaption) ; Should not Happen !?
MsgBox No Window Could Be found!`nhWnd: %hWnd%`nsCaption: %sCaption%
; return the caption to MS Word
COM_Invoke(hObj,"Caption=","")
return hWnd
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:36
; Function Name: Word_GetActiveHwnd()
;
; Returns the hWnd for the active Word Object's Window
;
; Syntax:
; Word_GetActiveHwnd()
; Parameters:
; None
; Return:
; Success = hWnd
; Failure = nothing
; **************************************************************************
Word_GetActiveHwnd() {
hWnd := Word_ObjGetHwnd(hObj := Word_Attach())
Word_Detach(hObj)
return hWnd
}
; **************************************************************************
; Author: ahklerner
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 14:45
; Function Name: Word_Activate()
;
; Activate & Show the Active Word Object
;
; Syntax:
; Word_Activate()
; Parameters:
; None
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Activate() {
WinActivate, % "ahk_id " hWnd := Word_GetActiveHwnd()
WinShow, % "ahk_id " hWnd
return
} |
03122010 - Updated syntax for the functions. _________________ Try Quick Search for Autohotkey or see the tutorial for newbies.
Last edited by sinkfaze on Fri Mar 12, 2010 3:54 pm; edited 1 time in total |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 12, 2010 3:02 am Post subject: |
|
|
Excellent! I will definitely be looking into this. Thanks man. _________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Fri Mar 12, 2010 6:53 am Post subject: |
|
|
Here are the re-written Excel functions from the first page, against please notify me of any errors as some of these are untested:
MS Excel:
| Code: | ; 03-12-2010 - The following functions originally created by NKRUZAN have been re-written
; by sinkfaze for compatability with AHK_L's object-oriented syntax.
; REQUIRES AHK_L and COM_L Standard Library
; **************************************************************************
; Author: NKRUZAN
; Language: AutoHotkey_L Rev 48
; Creation Date: 06/29/2008 21:35
; Function Name: Excel_GetCell()
;
; get text from the specified cell
;
; Syntax:
; Excel_GetCell(ColumnLetter, RowNumber)
;
; Example:
; MsgBox % Excel_GetCell("A", 1)
;
; Parameters:
; ColumnLetter = The column letter
; RowNumber = The row Number
; Return:
; Success = the value of the cell
; Failure = nothing
; **************************************************************************
Excel_GetCell(ColumnLetter, RowNumber) {
xl := COM_GetActiveObject("Excel.Application")
xl := xl.Cells[RowNumber,Excel_GetColumnIndex(ColumnLetter)]
Value := xl.Value
xl := ""
return Value
}
; **************************************************************************
; Author: NKRUZAN
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 16:47
; Function Name: Excel_SetText()
;
; Syntax:
; Excel_SetText(ColumnLetter, RowNumber, Text)
; Parameters:
; ColumnLetter = The column letter to put the text in
; RowNumber = The row Number to put the text in
; Text = The text to put in the cell
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Excel_SetText(ColumnLetter, RowNumber, Text) {
xl := COM_GetActiveObject("Excel.Application")
xl := xl.Cells[RowNumber,Excel_GetColumnIndex(ColumnLetter)]
xl.Formula := Text
xl := ""
return
}
; get the index corresponding to the column
; **************************************************************************
; Author: NKRUZAN
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 16:55
; Function Name: Excel_GetColumnIndex()
;
; Syntax:
; Excel_GetColumnIndex(ColumnLetter)
; Parameters:
; ColumnLetter =
; Return:
; Success =
; Failure =
; **************************************************************************
Excel_GetColumnIndex(ColumnLetter) {
local t1 := t2 := 0
StringUpper, ColumnLetter, ColumnLetter
Loop, Parse, ColumnLetter
t%A_Index% := Asc(A_LoopField) - 64
Return t2 ? (26 * t1) + t2 : t1
}
; **************************************************************************
; Author: NKRUZAN
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 16:54
; Function Name: Excel_Open()
;
; Create a new excel instance
;
; Syntax:
; Excel_Open()
; Parameters:
; None
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Excel_Open() {
xl := COM_CreateObject("Excel.Application")
xl.Visible := True
xl.Activate()
xl.Workbooks.Add()
xl := ""
return
}
Excel_Close() {
xl := COM_GetActiveObject("Excel.Application")
xl.Quit()
xl := ""
return
}
; **************************************************************************
; Author: NKRUZAN
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 16:55
; Function Name: Excel_OpenDoc()
;
; Open the specified document....
;
; Syntax:
; Excel_OpenDoc(FileName)
; Parameters:
; FileName = should be a FULL PATH
; Return:
; Success =
; Failure =
; **************************************************************************
Excel_OpenDoc(FileName) {
xl := COM_CreateObject("Excel.Application")
xl.Visible := True
xl.Activate()
xl.Workbooks.Open[FileName]
xl := ""
return
}
; **************************************************************************
; Author: NKRUZAN
; Language: AutoHotkey_L Rev 48
; Creation Date: 05/19/2008 16:55
; Function Name: Excel_GetActiveTitle()
;
;Get the title of the Active workbook open in Excel
;
; Syntax:
; Excel_GetActiveTitle()
; Parameters:
; None
; Return:
; Success =
; Failure =
; **************************************************************************
Excel_GetActiveTitle() {
xl := COM_CreateObject("Excel.Application")
xl.Visible := True
xl.Activate()
Name := xl.ActiveWorkbook.Name
xl := ""
return Name
} |
03122010 - Updated syntax for the functions. _________________ Try Quick Search for Autohotkey or see the tutorial for newbies.
Last edited by sinkfaze on Fri Mar 12, 2010 4:00 pm; edited 2 times in total |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 12, 2010 2:24 pm Post subject: |
|
|
Crap. Can you point me in the right direction of where to obtain the latest AHK_L? I've searched the forums, but I get various matches. Any idea as to what would be the best one? Thanks. _________________ -Jeremiah |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 12, 2010 2:59 pm Post subject: |
|
|
Thank you, sir. _________________ -Jeremiah |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|