AutoHotkey Community

It is currently May 26th, 2012, 11:26 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 296 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12, 13 ... 20  Next

Should this be continued?
Poll ended at June 18th, 2008, 11:34 pm
Yes 93%  93%  [ 14 ]
No 7%  7%  [ 1 ]
Total votes : 15
Author Message
 Post subject:
PostPosted: November 16th, 2009, 11:38 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Sean,

Looking for help using your examples for reading Word documents. I have successfully used it and implemented it with regards to on my own machine. However, the main use of my script is apparently being used on a Word document that is opening as protected and is not allowing me to read the text.

COM Error Notification wrote:
Function Name: "Text"
ERROR: (0X800A11FD)
PROG: Microsoft Word
DESC: This method or property is not available because the object refers to a protected area of the document.
HELP: C:\Program Files\Microsoft Office\Office10\1033\wdmain10.chm,37373

Will Continue?

Now, I have tried referring to MSDN help on ProtectedForForms, Unprotect, etc to unprotect it, but I am having difficulties. Here is what I've come up with.

Code:
Word_Unprotect()
{
   Word := Word_Attach("A") ; Attach to Active Window
   ActiveDocument := com_invoke(Word,"ActiveDocument")
;   CheckProtect := com_invoke(ActiveDocument,"","ProtectectionType")
   CheckProtect := com_invoke(ActiveDocument,"","ProtectedForForms")
   If CheckProtect <> 0
      Unprotect := com_invoke(ActiveDocument,"Unprotect")
   CheckProtect2 := com_invoke(ActiveDocument,"","ProtectectionType")
MsgBox, Debug:`nCheckProtect: %CheckProtect%`nCheckProtect2: %CheckProtect2%
   com_release(CheckProtect) ; cleanup
   com_release(Unprotect)
   com_release(ActiveDocument) ; cleanup
   com_release(Word) ; cleanup
   return DocText
}

Note, I need to check whether or not the document is already protected. If it is not protected, trying to again unprotect it will kick an error. So, first I want to see if it is protected. If so, unprotect it. Then I can read the text. After that, I want to reprotect it. If it was unprotected when checking, then just continue on.

Can you provide any assistance?

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 2:31 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I suggest to try to translate the VBA code again using (AutoHotkey_L,COM_L) or (AutoHotkeyU,COM_U). If you still can't with them, then come again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 5:12 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Honestly, I don't know VBA. I am basically guessing as to how this goes. I don't understand the syntax enough to modify it as I've never even used AHK_L. I've already spent many hours on this. If someone can just offer up an example of how to do this, I can adapt it to do what I need.

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 5:42 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
silveredge78 wrote:
Honestly, I don't know VBA.

Did you know there is a Macro Recorder in Word - it will give you the VBA for any actions you record :wink: Tools > Macro > Record New Macro ...

silveredge78 wrote:
... never even used AHK_L.

Unless Chris implements object support into the standard AHK release soon, you might want to start.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 6:06 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
When I try it and attempt to record Protecting a document, it stops the recorder and I get nothing. This is incredibly frustrating. I've spent 10+ hours on this already and I'm getting no where. It's not like I'm not trying. I just don't understand VBA. Theres a reason AHK appealed to me cause it made sense.

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 6:11 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
UNPROTECT THE DOCUMENT FIRST

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 6:23 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Tank> I am using an *unprotected* document and trying to automate *protecting* it. The recorder disappears as soon as I click Protect.

I tried to manually write out some VBA code to test things. I wrote it to protect the document (I start out with it unprotected), then to check if it's protected and if so, unprotect it again, setting a check variable. Then it checks to see if it is unprotected and if that check variable is true. If so, then it reprotects it.

Code:
Sub Word_Test()
    If ActiveDocument.ProtectionType = wdNoProtection Then
       ActiveDocument.Protect Type:=wdAllowOnlyFormFields
    End If
    If ActiveDocument.ProtectionType <> wdNoProtection Then
       ActiveDocument.Unprotect
       Check = True
    End If
    If ActiveDocument.ProtectionType = wdNoProtection Then
        If Check = True Then
            ActiveDocument.Protect Type:=wdAllowOnlyFormFields
        End If
    End If
End Sub

It doesn't go beyond protecting the document.

I'm at a loss here. Other than this protect/unprotect issue, I've been able to use what I need from this Word COM script set.

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 6:32 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
maybe this helps answer your question
http://msdn.microsoft.com/en-us/library/aa220366.aspx

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 8:04 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Tank> Thanks for the link, though I am already referring to it. I figured out what I was doing wrong with the VBA testing. I finally got that to work as I wanted. Now I am having issues converting it to AHK via the COM structure.

I am attempting to use it with the AHK_L and COM_L, but something is not right and now I'm getting additional errors.

Any help would be greatly appreciated. Particularly if someone can demonstrate how to determine if a word document is protected or not, then to unprotect if it is, then to reprotect after using Word_GetText().

Thanks in advance!

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 8:06 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Show what you have so far

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 10:30 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Tank> Here is what I have so far...

Code:
Word_Unprotect()
{
   Word := Word_Attach("A") ; Attach to Active Window
   ActiveDocument := com_invoke(Word,"ActiveDocument")
   CheckProtect := com_invoke(ActiveDocument,ProtectectionType)
MsgBox, Debug:`nCheckProtect: %CheckProtect%
   If CheckProtect <> 0
   {
      ProtectCheck = True
      Unprotect := com_invoke(ActiveDocument,"Unprotect")
   }
   com_release(CheckProtect) ; cleanup
   com_release(Unprotect)
   com_release(ActiveDocument) ; cleanup
   com_release(Word) ; cleanup
   Return, ProtectCheck
}

Word_Protect()
{
   Word := Word_Attach("A") ; Attach to Active Window
   ActiveDocument := com_invoke(Word,"ActiveDocument")
   Protect := com_invoke(ActiveDocument,"Protect","Type=wdAllowOnlyFormFields","NoReset=True")
   com_release(Protect)
   com_release(ActiveDocument) ; cleanup
   com_release(Word) ; cleanup
}

Word_GetText()
{
   ProtectCheck := Word_Unprotect()
MsgBox, Debug:`nProtectCheck in Word_Protect: %ProtectCheck%
   Word := Word_Attach("A") ; Attach to Active Window
   ActiveDocument := com_invoke(Word,"ActiveDocument")
   Range := com_invoke(ActiveDocument,"Range")
   DocText := com_invoke(Range,"Text") ; get the document text
   If ProtectCheck = True
      Word_Protect()
   com_release(Range) ; cleanup
   com_release(ActiveDocument) ; cleanup
   com_release(Word) ; cleanup
   return DocText
}

Things that don't seem to work right:
    1) In Word_Unprotect, it doesn't give the correct value for CheckProtect. It should be something like wdAllowOnlyFormFields or wdNoProtect. Instead, it's 0. On random occasions it has been 1 or 2, but not consistently.

    2) Word_Protect gives the error about a Type mismatch (refer to my original post).
If you or anyone can help at all, I would sincerely appreciate it.

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 10:40 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Ok first point of confusion is it wont return wdAllowOnlyFormFields or wdNoProtect. instead a numeric value from the vba editor right click and get the quick info on such a variable to get its numeric counterpart. this is what you will expect to test in AHK
0 is false

same thing with the word protect function

wdAllowOnlyFormFields = 2 for instance so instead of Type=wdAllowOnlyFormFields put 2
for Type=wdAllowOnlyFormFields NoReset=True substitute the number 1 for this
this is a commons source of confusin i hope this responce helps

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2009, 1:02 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
OK, this code will require (AutoHotkey_L,COM_L) or (AutoHotkeyU,COM_U).
Code:
Word := COM_GetActiveObject("Word.Application")
ActiveDocument := Word.ActiveDocument
ProtectionType := ActiveDocument.ProtectionType
If   ProtectionType <> -1
   ActiveDocument.Unprotect()
; <- add your code
If   ProtectionType <> -1
   ActiveDocument.Protect(ProtectionType,True)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 9:04 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Sean> Thanks! That seems to work. However, for some reason, it only works like twice before the script bombs out.

Here are the functions as I modified them from the originals in this script to what I gather is the proper syntax for AHK_L:

Code:
; Revisions by silveredge78 to be usable for COM_L based on syntax from Sean.
; v0.1.1, 11/19/09
; - Revising the other functions to use the COM_L syntax.
; - Clean up documentation & code to my standards.
;
; v0.1.0, 11/17/09
; - Initial attempts at modifying Word_GetText() using unprotect/protect
;   features.
;
; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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:
; 1)   Text   = the text string to insert into the document   
; Return:
;    Success = nothing
;    Failure = nothing
; **************************************************************************
Word_InsertText(Text)
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  Selection := Word.Selection                                               ; Get Insertion Point or Selected text
  Selection.TypeText(Text)                                                  ; Put the text there
  COM_Release(Selection)                                                    ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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()
{
  Word := Word_Attach("N")                                                  ; Attach to Active Window
  Documents := Word.Documents
  Documents.Add()                                                           ; Add a new document
  Documents.Select()                                                        ; Select it
  COM_Release(Documents)                                                    ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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()
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  Word.Quit()                                                               ; Quit all instances
  COM_Release(Word)                                                         ; Cleanup
}

; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; Creation Date:   05/19/2008   14:18
; Function Name:   Word_SaveAs()
;
; Syntax:
;    Word_SaveAs(SaveFileName)
; Parameters:
; 1)   SaveFileName   = The name to save the file as. Must be Full Path   
; Return:
;    Success =
;    Failure =
; **************************************************************************
Word_SaveAs(SaveFileName)
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  ActiveDocument := Word.ActiveDocument                                     ; Get the active document
  ActiveDocument.SaveAs(SaveFileName, wdFormatDocument := 0)                ; Save the file
  COM_Release(ActiveDocument)                                               ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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()
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  ActiveDocument := Word.ActiveDocument                                     ; Get the active document
  ActiveDocument.Save()                                                     ; Save file
  COM_Release(ActiveDocument)                                               ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; Creation Date:   05/19/2008   14:19
; Function Name:   Word_OpenDoc()
;
; Syntax:
;    Word_OpenDoc(FileName)
; Parameters:
; 1)   FileName   = The file name to open   
; Return:
;    Success = nothing
;    Failure = nothing
; **************************************************************************
Word_OpenDoc(FileName)
{
  Word := Word_Attach("N")                                                  ; Attach to Active Window
  Documents := Word.Documents
  Documents.Open(FileName)                                                  ; Open file
  COM_Release(Documents)                                                    ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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()
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  ActiveDocument := Word.ActiveDocument                                     ; Get the active document
  Name := ActiveDocument.Name                                               ; Get the document name
  COM_Release(ActiveDocument)                                               ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
  Return, Name
}

;get document text


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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()
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  ActiveDocument := Word.ActiveDocument                                     ; Get the active document
  ProtectionType := ActiveDocument.ProtectionType                           ; Determine the protection level of the document
;MsgBox, Debug:`nProtectionType: %ProtectionType%                           ; For testing, enabled
  If ProtectionType <> -1                                                   ; If protection is set to wdAllowOnlyFormFields, then Unprotect
    ActiveDocument.Unprotect()
  Range := ActiveDocument.Range
  DocText := Range.Text                                                     ; Read the text of the file
  If ProtectionType <> -1                                                   ; If protection had been set, then reprotect
    ActiveDocument.Protect(ProtectionType,True)
  COM_Release(Range)                                                        ; Cleanup
  COM_Release(ProtectionType)                                               ; Cleanup
  COM_Release(ActiveDocument)                                               ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
  Return, DocText                                                           ; Return filetext
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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()
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  Selection := Word.Selection
  SelText := Word.Selection(Text)                                           ; Get the selected text
  COM_Release(Selection)                                                    ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
  Return, SelText
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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:
; 1)   sFontName="Times New Roman"   =    The name of the font to use
; 2)   sFontSize="10"   =    The font size
; 3)   bBold=0   =    True or False Bold
; 4)   bItalic=0   =    True or False Italic
; 5)   bCaps=0   =    True or False All Caps
; Return:
;    Success = nothing
;    Failure = nothing
; **************************************************************************
Word_SetCurrentFont(sFontName="Times New Roman",sFontSize="10",bBold=0,bItalic=0,bCaps=0)
{
  Word := Word_Attach("A")                                                  ; Attach to Active Window
  Selection := Word.Selection
  Font := Selection.Font
  Font.Name(sFontName)                                                      ; Font Name
  Font.Size(sFontSize)                                                      ; Font Size
  Font.Bold(bBold)                                                          ; Bold
  Font.Italic(bItalic)                                                      ; Italic
  Font.AllCaps(bCaps)                                                       ; Caps
  COM_Release(Font)                                                         ; Cleanup
  COM_Release(Selection)                                                    ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; Creation Date:   05/19/2008   14:24
; Function Name:   Word_Detach()
;
; COM_Release wrapper for consistency
;
; Syntax:
;    Word_Detach(ObjWord)
; Parameters:
; 1)   ObjWord   =    Handle to already opened object
; Return:
;    Success = nothing
;    Failure = nothing
; **************************************************************************
Word_Detach(ObjWord)
{
  COM_Release(ObjWord)
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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:
; 1)   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
  ;Get The Last Used Instance
  If (sInstance = "A")                                                      ; Active Window - Default
  {
    ObjWord := COM_GetActiveObject("Word.Application")                      ; Attach to Active Window
    ObjWord.Visible(True)
    ObjWord.Activate()
  }
  Else If (sInstance = "N")                                                 ; New Window
  {
    ObjWord := COM_CreateObject("Word.Application")
    ObjWord.Visible(True)
    ObjWord.Activate()
  }
  Return, ObjWord
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; Creation Date:   05/19/2008   14:31
; Function Name:   Word_ObjGetHwnd()
;
; Gets the hWnd for a given Word object
;
; Syntax:
;    Word_ObjGetHwnd(hObj)
; Parameters:
; 1)   hObj   = Handle to word object
; Return:
;    Success = hWnd to hObj 's parent window
;    Failure = nothing
; **************************************************************************
Word_ObjGetHwnd(hObj)
{
  DetectHiddenWindows, On
  SetTitleMatchMode, 2
  Random, UUID, 10000, 999999
  sCaption := "[" . UUID . "]"                                              ; Generate a unique title - http://support.microsoft.com/kb/310744
  hObj.Caption(sCaption)                                                    ; Set the title of the window
  sCaption := hObj.Caption                                                  ; Get the current 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%
  hObj.Caption()                                                            ; Return the caption to MS Word
  Return, hWnd
}


; **************************************************************************
; Author:   ahklerner
; Language:   AutoHotkey v1.0.47.06
; 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 v1.0.47.06
; Creation Date:   05/19/2008   14:45
; Function Name:   Word_Activate()
;
; Activate & Show the Active Word Object
;
; Syntax:
;    Word_Activate()
; Parameters:
;   None
; Return:
;    Success =
;    Failure =
; **************************************************************************
Word_Activate()
{
  WinActivate, % "ahk_id " . hWnd := Word_GetActiveHwnd()
  WinShow, % "ahk_id " . hWnd
}

The two that I use in my script are Word_GetText() and from there it calls Word_Attach(). I cannot figure out why it is unstable.

Can someone take a look at my code and tell me what I'm messing up and is it due to the COM_L implementation? Or is it how it's compiling somehow? I'm at a loss. I use the above noted functions in my include, as well as COM_L. Here is my code:

Code:
^+c::
  GoSub, ActiveWordCheck                                                    ; Check to make sure Word is the active window
  WordText := Word_GetText()
  GoSub, ClearVariables

  Loop, Parse, WordText, 
  {
    If A_Index = 2
      PatientName := RegExReplace(A_LoopField, "\s$|\s\s$", "")
    If A_LoopField contains scribed HPI
      Goto, VersionError
  }

  Loop, Parse, WordText, 
  {
    If A_Index = 4
      Account := CopyCheck(A_LoopField)
    If A_Index = 27
      Allergies := CopyCheck(A_LoopField)
    If A_Index = 81
      FH_Gen := CopyCheck(A_LoopField)
    If A_Index In 83,89,95,101,107,114,120,126,132,139,145,151,157
      Medications := CopyCheck(A_LoopField,Medications)
    If A_Index In 86,92,98,104
      PMD := CopyCheck(A_LoopField,PMD)
    If A_Index = 88
      FH_CAD := CopyCheck(A_LoopField)
    If A_Index = 94
      FH_Cancer := CopyCheck(A_LoopField)
    If A_Index = 100
      FH_CVA := CopyCheck(A_LoopField)
    If A_Index = 106
      FH_DM := CopyCheck(A_LoopField)
    If A_Index In 111,117,123,129
      CPL := CopyCheck(A_LoopField,CPL)
    If A_Index = 113
      FH_HTN := CopyCheck(A_LoopField)
    If A_Index = 119
      FH_Thyroid := CopyCheck(A_LoopField)
    If A_Index = 125
      SH_Gen := CopyCheck(A_LoopField)
    If A_Index = 131
      SH_Caffeine := CopyCheck(A_LoopField)
    If A_Index In 136,142,148,154
      Surgeries := CopyCheck(A_LoopField,Surgeries)
    If A_Index = 138
      SH_ETOH := CopyCheck(A_LoopField)
    If A_Index = 144
      SH_Tobacco := CopyCheck(A_LoopField)
    If A_Index = 150
      SH_Drugs := CopyCheck(A_LoopField)
  }

  MsgBox, 0, %ScriptName%, Copy completed for %PatientName% (%Account%).
Return

^+v::
  GoSub, ActiveWordCheck                                                    ; Check to make sure Word is the active window
  WordText := Word_GetText()
  Loop, Parse, WordText, 
  {
    If A_Index = 2
      NewPatientName := RegExReplace(A_LoopField, "\s$|\s\s$", "")
    If A_Index = 4
      NewAccount := CopyCheck(A_LoopField)                                     ; Account Number
  }

  If (Account != NewAccount) Or (PatientName != NewPatientName)
  {
    NewDocumentID := WinExist("A")
    MsgBox, 262452, %ScriptName% - Warning, The patient name or account number for this `npaste does not match the currently stored copy.`n`nCopy Information:`nPatient Name: %PatientName%`nAccount #: %Account%`n`nPaste Information`nPatient Name: %NewPatientName%`nAccount #: %NewAccount%`n`nWould you like to proceed with the paste?
    IfMsgBox, No
      Return
    WinActivate, ahk_id %NewDocumentID%
  }

  SendInput, {Ctrl Up}{Shift Up}
  SendInput, ^{Home}
  Sleep, 200
  SendInput, {Tab 9}
  Sleep, 100
  SendInput, %SH_Gen%{Tab}
  Sleep, 100
  SendInput, %Allergies%{Tab}
  Sleep, 100
  SendInput, %PMD%{Tab}
  Sleep, 100
  SendInput, %FH_CAD%{Tab}
  Sleep, 100
  SendInput, %Medications%{Tab 2}
  Sleep, 100
  SendInput, %FH_Cancer%{Tab}
  Sleep, 100
  SendInput, %FH_CVA%{Tab}
  Sleep, 100
  SendInput, %FH_DM%{Tab}
  Sleep, 100
  SendInput, %CPL%{Tab}
  Sleep, 100
  SendInput, %FH_HTN%{Tab 2}
  Sleep, 100
  SendInput, %FH_Thyroid%{Tab}
  Sleep, 100
  SendInput, %FH_Gen%{Tab}
  Sleep, 100
  SendInput, %SH_Caffeine%{Tab}
  Sleep, 100
  SendInput, %SH_ETOH%{Tab}
  Sleep, 100
  SendInput, %Surgeries%{Tab}
  Sleep, 100
  SendInput, %SH_Drugs%{Tab}
  Sleep, 100
  SendInput, %SH_Tobacco%{Tab 2}
  Sleep, 100
  SendInput, %SH_Occupation%
  Sleep, 100

  MsgBox, 0, %ScriptName%, Paste complete for %NewPatientName% (%NewAccount%).
Return

ActiveWordCheck:
  Loop
  {
    If WinActive("ahk_class OpusApp") = 0x0
    {
      MsgBox, 262197, %ScriptName%, There is not a Microsoft Word Document active.  If you would like to`nretry`, please select the appropriate Microsoft Word Document and`npress Retry.  Otherwise`, press Cancel to end the hotkey.
      IfMsgBox, Cancel
        Exit
    }
    Else
      Break
    Sleep, 100
  }
Return

Any help would be greatly appreciated - Either with my code or my compiling/instability woes.

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 9:49 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
I think I narrowed it down. It seems to relate to the COM_Release(ProtectionType). When I comment that out, it goes just fine.

Here is what I am using while trying to narrow it down:

Code:
Word_GetText()
{
  Word := COM_GetActiveObject("Word.Application")
  ActiveDocument := Word.ActiveDocument                                     ; Get the active document
  ProtectionType := ActiveDocument.ProtectionType                           ; Determine the protection level of the document
MsgBox, Debug:`nProtectionType: %ProtectionType%                           ; For testing, enabled
  If ProtectionType <> -1                                                   ; If protection is set to wdAllowOnlyFormFields, then Unprotect
    ActiveDocument.Unprotect()
  Range := ActiveDocument.Range
  DocText := Range.Text                                                     ; Read the text of the file
  If ProtectionType <> -1                                                   ; If protection had been set, then reprotect
  ActiveDocument.Protect(ProtectionType,True)
  COM_Release(Range)                                                        ; Cleanup
MsgBox, Debug:`nBefore ProtectionType
;  COM_Release(ProtectionType)                                               ; Cleanup
MsgBox, Debug:`nAfter ProtectionType
  COM_Release(ActiveDocument)                                               ; Cleanup
  COM_Release(Word)                                                         ; Cleanup
  Return, DocText                                                           ; Return filetext
}

Any reason why that command would be causing an issue?

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 296 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12, 13 ... 20  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group