 |
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 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Mon Aug 25, 2008 4:56 am Post subject: |
|
|
ahklerner -
Made a couple of Word automation functions for myself, figured I might as well post them here. Feel free to add them to the library or not. I used the same format as you did for the function description.
| Code: | ; **************************************************************************
; Author: Krogdor
; Language: AutoHotkey v1.0.47.06
; Creation Date: 08/24/2008
; Function Name: Word_Align()
;
; Align specified paragraph (Right/Center/Left, and Justify)
;
; Syntax:
; Word_Align(Paragraph,Alignment)
; Parameters:
; 1) Paragraph = The paragraph number that is to be aligned. Any places where
; there is a newline counts as a new paragraph, so blank lines count as well.
; 2) Alignment = How to align it:
; 0 = Left (default)
; 1 = Center
; 2 = Right
; 3 = Justify
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Align(Para = 1, Alignment = 0) {
If (Alignment < 0 || Alignment > 3)
Alignment = 0
Word_Attach("A")
ActiveDocument := COM_Invoke(Word,"ActiveDocument")
Paragraphs := COM_Invoke(ActiveDocument, "Paragraphs", Para)
COM_Invoke(Paragraphs,"Alignment=",Alignment)
COM_Release(Word)
COM_Release(ActiveDocument)
COM_Release(Paragraphs)
}
; **************************************************************************
; Author: Krogdor
; Language: AutoHotkey v1.0.47.06
; Creation Date: 08/22/2008
; Function Name: Word_Header()
;
; Insert a header into the document with specified text.
;
; Syntax:
; Word_Header(Text,Style)
; Parameters:
; 1) Text = the text string to insert into the document
; 2) Style = which pages to insert on:
; 1 = All pages (default)
; 2 = First page
; 3 = Even pages
; Return:
; Success = nothing
; Failure = nothing
; **************************************************************************
Word_Header(Text, Style = 1, Word = "") {
If (Style < 1 || Style > 3)
Style = 1
Word_Attach("A")
ActiveDocument := COM_Invoke(Word,"ActiveDocument")
Section := COM_Invoke(ActiveDocument,"Sections",1)
COM_Invoke(COM_Invoke(COM_Invoke(Section,"Headers",Style),"Range"),"Text",Text)
COM_Release(ActiveDocument)
COM_Release(Word)
COM_Release(Section)
} |
|
|
| Back to top |
|
 |
rares Guest
|
Posted: Mon Aug 25, 2008 12:14 pm Post subject: help with script |
|
|
hello i have the following script:
COM_Init()
Sleep 1000
Word_InsertText("cat")
COM_Term()
exitapp
#include com.ahk
Word_InsertText(Text){
oWord := COM_GetActiveObject("Word.Application") ; Attach to Active Window
oSelection := COM_Invoke(oWord,"Selection") ; Get Insertion Point or Selected text
COM_Invoke(oSelection,"TypeText",dog) ; Put the text there
COM_Release(oSelection) ; cleanup
COM_Release(oWord) ; cleanup
}
Word_Open(){
oWord := COM_CreateObject("Word.Application") ; Attach to New Window
oDocuments := COM_Invoke(oWord, "Documents")
COM_Invoke(oWord,"Visible=",True)
COM_Invoke(oWord,"Activate")
COM_Invoke(oDocuments,"Add") ; Add a new document
COM_Invoke(oDocuments,"Select") ; Select it
COM_Release(oDocuments) ; cleanup
COM_Release(oWord) ; cleanup
}
it's sopose to put the words specified by me after certain words that it finds in the word document . For example, the script finds the word " dog ", I want it to paste the word "cat " after the word "dog"!
I want you guys to help me, if you can. I want to add more words for the computer to search and add after them the words i specify, resembling auto complete in Opera or the magic wand. |
|
| Back to top |
|
 |
ABCza
Joined: 03 Jun 2008 Posts: 22 Location: Italy
|
Posted: Sat Nov 29, 2008 3:09 am Post subject: |
|
|
Hi
I'm not much involved in COM things; there's a way to loop the document paragraphs in MS Word? I mean something like:
Paragraph_1
ssdfjhsdfjksdhfhsjkdhfkjhfsjkdfkjsdhfjsdfdkhfhsdjfhsdkfjkdfsdj sdfsdjkfkj sdfjkhsdfkhsdjf sdfjksdhfhsdfjksdhf sdfjsdfh
Paragraph_2
sdfsdfhjsdhfsdjkf sdfjkhsdjkfsdjhfjksdhfjkshdfjks sdfjksdjkfdjkfdjk
skdjfjksdfjksjkdhfjkfsdjk sdjksdjkfhjk
Paragraph_3
dkjfgkljdfgjdfjgkljdfgkldfjklgd weruioruu werwuriouwer iowe mklmdgkldfklgjklj werpoweirpwero m,.fng,dfnfm,gm _________________ ABCza |
|
| 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
|