AutoHotkey Community

It is currently May 27th, 2012, 6:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: October 20th, 2010, 7:53 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
I do have the latest ahk_l version with the com_l file

Using notepad++ "exec plugging" the script runs fine. IE passing everything in command line.

C:\Program Files\AutoHotkey\AutoHotkey.exe "$(FULL_CURRENT_PATH)" "C:\Documents and Settings\user\Desktop\Summary_Word_Documents\Ready for client\1404301r.doc"


But if I drag and drop files on my script It gives me the following error.


---------------------------
COM Error Notification
---------------------------
Function Name: "Visible"
ERROR: The COM Object may not be a valid one!
()

Will Continue?
---------------------------
Yes No
---------------------------

At the top of my script I have.

Code:
Loop %0% ; For each parameter aka file dropped onto a script
{
...;;;;EDIT  ADDED code to show where LongPath is set.
...     GivenPath := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
    Loop %GivenPath%, 1
   {
        LongPath = %A_LoopFileLongPath%
   }
...
...
   com_CoInitialize() ; Initialize COM
;;line above is successfull
   Word_OpenDoc( LongPath) ; Opens a New Document
...
...
}

Word_OpenDoc(FileName){
   Word := Word_Attach("N") ; Attach to New Window
;;;;;;;;;;Crashes here.  (tested with exitapp) and get the error message before script closes.
   Documents := com_Invoke(Word, "Documents")
   com_invoke(Documents,"Open",FileName) ; open file
   com_release(Documents) ; cleanup
   com_release(Word) ; cleanup
   }

;;EDIT unchanged code just forgot a function which may help solve.

Word_Attach(sInstance="A"){
   SetWinDelay, 0
   ;Get The Last Used Instance
   if (sInstance = "A") { ; Active
      ObjWord := COM_GetActiveObject("Word.Application")
      COM_Invoke(ObjWord,"Visible=",True)
      COM_Invoke(ObjWord,"Activate")
      }
   Else if (sInstance = "N") { ; New
      ObjWord := com_CreateObject("Word.Application")
      COM_Invoke(ObjWord,"Visible=",True)
      COM_Invoke(ObjWord,"Activate")
      }
   return ObjWord
   }




Can anyone point me to the right direction to solve my problem..
Thank you.

_________________
-=Raz=-


Last edited by Razlin on October 21st, 2010, 5:43 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2010, 8:05 pm 
Online
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
so where in the script is the variable longpath set?

_________________
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: October 20th, 2010, 8:11 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
On a side note, you shouldn't even need COM_L to do what you're doing:
Code:
Process, Exist, WINWORD.exe
if Errorlevel
  oWord := ComObjActive("Word.Application")
else,
  oWord := ComObjCreate("Word.Application")
  , oWord.Visible := true 
 
 
oDoc := oWord.Documents.Open(FileName)

Someone should prolly update the MS Office Functions Library to work with AHK_L sometime...

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on October 20th, 2010, 8:17 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2010, 8:11 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
Added in top script.

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2010, 8:21 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
Honestly Im not to familiar with com altogether.
and if I need it or not.. I was using ahklearners code for word.

Everything seems to work 100% for my "save as .html" from (word to html) and I do manipulation after to fix microsofts sucky html conversion.

What I'm wondering is why does it work from command line but not when I drag and drop to my script.

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2010, 8:40 pm 
Are you using the Unicode version of AHK_L & COM_L (or ANSI version on both)? If you're using Unicode, is you file encoding of your script UTF-8?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2010, 9:04 pm 
Offline

Joined: February 29th, 2008, 8:36 pm
Posts: 901
Location: Vault 7
Well... if it runs fine one way but not the other, try the following for both ways:
  • what is the value of A_WorkingDir right before the problematic line?
  • What does the script think its command line is... try DllCall("GetCommandLineA","AStr")

_________________
ImageDebugging,Container,FileContainer,Object Preferences,ShellFileOperation


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2010, 2:54 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
@Rapte_Of_Suzaku.

you may be on to something..
Using the dllcall I got 2 different results which may be the cause of the errors.

A_workingdir where the same on both occurences

---------------------------
negoteck.ahk
---------------------------
"C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Documents and Settings\user\Desktop\negoteck.ahk" "C:\Documents and Settings\xxxxxxxx\Desktop\Summary_Word_Documents\Ready for Negotech\1404301r.doc"
---------------------------
OK
---------------------------

---------------------------
negoteck.ahk
---------------------------
"C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Documents and Settings\user\Desktop\negoteck.ahk" C:\DOCUME~1\xxxxxx~1.xxx\Desktop\SUMMAR~1\READYF~1\1306503s.doc
---------------------------
OK
---------------------------


@a4u. I have intalled the unicode version. I'll check the UTF-8 possibility as well.. thanks.


@jethrow
Not sure how to get my save as function to work in word. I looked up examples online and found


com_invoke(ActiveDocument,"SaveAs", SaveFileName, wdFormatDocument := 10) ; Save the file 10 is html

if theres an easyer way to do so without com... all the better. alas.. thats what I found to work best.

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2010, 3:00 pm 
Quote:
@jethrow
Not sure how to get my save as function to work in word. I looked up examples online and found

com_invoke(ActiveDocument,"SaveAs", SaveFileName, wdFormatDocument := 10) ; Save the file 10 is html

if theres an easyer way to do so without com... all the better. alas.. thats what I found to work best.

That's the AHK Basic way of doing it (so to speak) using the COM library. It's not that jethrow's example wasn't using COM, just it's using the AHK_L Native COM rather than an external Library. So, your example would in AHK_L Native COM would be:
Code:
oDoc.SaveAs(SaveFileName, wdFormatDocument := 10) ; Save the file 10 is html


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2010, 4:20 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
I see..

Not sure whats native and whats not in ahk. Thanks for the clarification though.

PS.. where do you get the list of "functions" for objects..

IE.

oWord.SaveAs
oWord.Visible
oWord.Document.open.....

and there more then likely not "Functions" what is the correct term for such references.

I wish college programming would show us more useful things then how to write "hello world" in 30 different languages.

and have decent teachers that actually knew the language and not read from the text books.

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2010, 4:36 pm 
Quote:
Not sure whats native and whats not in ahk

Basically, if you're using the COM Library, you are NOT using Native COM.
Code:
oWord := COM_GetActiveObject("Word.Application") ; COM Library
oWord := ComObjActive("Word.Application") ; Native COM

Quote:
where do you get the list of "functions" for objects..

MSDN is prolly the best place. Here's links for the Application Object & Document Object. Also, the Macro Recorder in the MS Office Apps can be very helpful...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2010, 4:42 pm 
Offline

Joined: February 29th, 2008, 8:36 pm
Posts: 901
Location: Vault 7
Razlin wrote:
PS.. where do you get the list of "functions" for objects

That's the hardest part about COM. MSDN is you friend with this. Search it for "Word.Application". Sometimes you find what you are looking for quickly. Othertimes, be prepared to dig.

Razlin wrote:
what is the correct term for such references.

Methods

Razlin wrote:
I wish college programming would show us more useful things

+1. Going into college, I decided to be a computer engineer rather than do straight up computer science because I knew I'd be able to learn programming better on my own. Concepts are more important than specifics.


from the results of my debugging tips, it seems that maybe COM doesn't like short paths? So try this to always use the long path:
Code:
GivenPath := %A_Index%
Loop, %GivenPath%
   GivenPath:= A_LoopFileLongPath

_________________
ImageDebugging,Container,FileContainer,Object Preferences,ShellFileOperation


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2010, 5:43 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
Thank you all so much for the info. Seriously.. Thank you.

It was indeed the LongPath's which where the entire reason for it not working. Ugh...

Aside from my on stupid error I have learned a lot from my post and thank you.

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, Bing [Bot], dra, HotkeyStick, migz99, Wicked, XstatyK and 56 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