AutoHotkey Community

It is currently May 26th, 2012, 11:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 646 posts ]  Go to page Previous  1 ... 14, 15, 16, 17, 18, 19, 20 ... 44  Next
Author Message
 Post subject:
PostPosted: October 21st, 2008, 7:50 am 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Sean

can you help, how to get the objUser address ?
or just get the Instance of specific COM instance by COM_GetObject ,
if I know the Address of this instance ?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 6th, 2008, 12:14 pm 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
How can i pass a number that has zero in the beginning to com_invoke?
So the number should probably be passed as text. Invoke() thinks it's a number so it strips the zero away.

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 6th, 2008, 12:43 pm 
amokoura wrote:
How can i pass a number that has zero in the beginning to com_invoke?

I recommend AutoIt instead of AHK.


Report this post
Top
  
Reply with quote  
PostPosted: November 6th, 2008, 1:49 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
amokoura wrote:
How can i pass a number that has zero in the beginning to com_invoke?
So the number should probably be passed as text. Invoke() thinks it's a number so it strips the zero away.
Code:
"0" vs 0

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 7th, 2008, 9:01 am 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
tank wrote:
Code:
"0" vs 0

Thanks, but didn't help. Here's how I tested:
Code:
COM_InvokeDeep(oExcel, "ActiveSheet.Range[A1].Value", "012354")


It sets the cell value to "12345". I've set the cell format to Text, so it supports zero-beginning numbers.

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 11:28 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Only built-in functions are capable of distinguishing between numeric literals and string literals. 0 and "0" both end up as a character string when assigned to a parameter of a script function.

You can force the value to be passed to the COM object's method as a specific type by using COM_Invoke_. Instead of
Code:
COM_Invoke(obj, "Method", value)
use
Code:
COM_Invoke_(obj, "Method", 8, value)
8 is VT_BSTR, which indicates a COM string value.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 1:19 pm 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
Lexikos wrote:
[...] use
Code:
COM_Invoke_(obj, "Method", 8, value)
8 is VT_BSTR, which indicates a COM string value.


Thanks, that works like a charm!

_________________
I recommend AutoIt instead of AHK.


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

Joined: July 22nd, 2008, 1:49 pm
Posts: 151
Hi. I'm trying to make a script that prints one sheet of a excel document. But i'm really new to using the COM library, so could use a hand in doing this right :)

Used record macro to get this:
Code:
Sheets("Ark3").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True


Tried transformorning this, but can not really get it to work.

Code:
COM_Invoke(Sheets, "Select", Ark3) ; should it be "Ark3" ?
COM_Invoke(Activewindow, "selectedsheets.printout", Copies:= 1, Collate:=True

Would be awesome if someone had the time to point out my mistakes. Thanks for your time.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2008, 2:45 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
totalmig wrote:
Code:
... Copies:=1, Collate:=True

I'd like to comment that COM.ahk does not support the above syntax, and probably will never do.
(I don't think VBScript/JScript do either. Only VBA does, I suppose.)
Fortunately in your case, however, I think you can simply use:
Code:
COM_Invoke(COM_Invoke(objExcel, "Sheets", "Ark3"), "Select")
COM_Invoke(COM_Invoke(COM_Invoke(objExcel, "ActiveWindow"), "SelectedSheets"), "PrintOut")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2008, 4:02 pm 
Offline

Joined: July 22nd, 2008, 1:49 pm
Posts: 151
Ohh that sounds great. I simply tried using that because i couldn't think of no other ways. what you have posted looks great :)

And thanks a million for making it possible to do this with AHK for thoose of us who sucks at programming.

EDIT:

Tried using this, but keep getting "The COM object might not be a valid one"

This is the code i'm using:

Code:
Print:
Gui, Submit , NoHide
if 1 =
{
msgbox Nothing to print
}
else
{
Process, Close, %autopid%
run P:\test.xls,, HIDE
COM_Invoke(COM_Invoke(objExcel, "Sheets", "Ark3"), "Select")
COM_Invoke(COM_Invoke(COM_Invoke(objExcel, "ActiveWindow"), "SelectedSheets"), "PrintOut")
msgbox printing
}
return


Any help would be much appriciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 1:56 pm 
Offline

Joined: July 22nd, 2008, 1:49 pm
Posts: 151
Btw, I'm using Excel 2003 on XP.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 2:16 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
changes in red
sean or Lexikos may yet correct me here but i dont think so
Untested by the way :?
Code:
Print:
Gui, Submit , NoHide
if 1 =
{
msgbox Nothing to print
}
else
{
Process, Close, %autopid%
;run P:\test.xls,, HIDE
pxl := ActiveXObject("Excel.Application")
objExcel:=COM_Invoke(pxl,"Open","P:\test.xls")

COM_Invoke(sheetArk3:=COM_Invoke(objExcel, "Sheets", "Ark3"), "Select")
COM_Invoke(SheetReference:=COM_Invoke(activeWorkbo0k:=COM_Invoke(objExcel, "ActiveWindow"), "SelectedSheets"), "PrintOut")
COM_Release(SheetReference)
COM_Release(activeWorkbo0k)
COM_Release(sheetArk3)
COM_Release(objExcel)
COM_Invoke(pxl,"Quit")

msgbox printing
}
return

_________________
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 20th, 2008, 3:02 pm 
Offline

Joined: July 22nd, 2008, 1:49 pm
Posts: 151
Thanks for your input and fast response.

Tried using this, but still getting "The COM object might not be a valid one" on pretty much everything.

Code:
#Include Cohelper.ahk
#include COM.ahk

run N:\06 lejlighedstjek\Program\autofinish.exe,,,autopid

Gui, Add, Text, x36 y30 w360 h30 , Print 10 lejligheder af gangen
Gui, Add, Edit, x36 y70 w180 h20 v1, Fisk
Gui, Add, Edit, x36 y100 w180 h20 v2,
Gui, Add, Edit, x36 y130 w180 h20 v3,
Gui, Add, Edit, x36 y160 w180 h20 v4,
Gui, Add, Edit, x36 y190 w180 h20 v5,
Gui, Add, Edit, x36 y220 w180 h20 v6,
Gui, Add, Edit, x36 y250 w180 h20 v7,
Gui, Add, Edit, x36 y280 w180 h20 v8,
Gui, Add, Edit, x36 y310 w180 h20 v9,
Gui, Add, Edit, x36 y340 w180 h20 v10,
Gui, Add, Button, x36 y380 w180 h50 Gprint, PRINT
Gui, Show, x350 y228 h467 w252, MegaPrint
return

Print:
Gui, Submit , NoHide
if 1 =
{
msgbox Intet at printe.
}
else
{
Process, Close, %autopid%
pxl := ActiveXObject("Excel.Application")
objExcel:=COM_Invoke(pxl,"Open","P:\test.xls")
COM_Invoke(sheetArk3:=COM_Invoke(objExcel, "Sheets", "Ark3"), "Select")
COM_Invoke(SheetReference:=COM_Invoke(activeWorkbo0k:=COM_Invoke(objExcel, "ActiveWindow"), "SelectedSheets"), "PrintOut")
COM_Release(SheetReference)
COM_Release(activeWorkbo0k)
COM_Release(sheetArk3)
COM_Release(objExcel)
COM_Invoke(pxl,"Quit")
msgbox printer
}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 4:05 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
objExcel represents Excel.Application. There exist various examples to create/obtain it in the forum, so you may search. Here is another example than tank's one:
Code:
run P:\test.xls,, HIDE
; Process, Wait, Excel.exe
COM_Init()
objExcel := COM_GetActiveObject("Excel.Application")
COM_Invoke(COM_Invoke(objExcel, "Sheets", "Ark3"), "Select")
COM_Invoke(COM_Invoke(COM_Invoke(objExcel, "ActiveWindow"), "SelectedSheets"), "PrintOut")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2008, 10:40 am 
Offline

Joined: July 22nd, 2008, 1:49 pm
Posts: 151
Thanks alot for your help. I know that i've probably been given a billion hints already, but i still really cant get this to work. Hope someone still has enough patience to point me in the right direction.

Code:
Print:
Gui, Submit , NoHide
if 1 =
{
msgbox Intet at printe.
}
else
{
Process, Close, %autopid%
COM_Init()
objExcel := COM_GetActiveObject("Excel.Application")
COM_Invoke(COM_Invoke(objExcel,"Worksbooks"), "Open","P:\test.xls") 
COM_Invoke(COM_Invoke(objExcel, "Sheets", "Ark3"), "Select")
COM_Invoke(COM_Invoke(COM_Invoke(objExcel, "ActiveWindow"), "SelectedSheets"), "PrintOut")
msgbox printer
}
return


Getting:
Function name: "Worksbooks"
Error: "Unknown name" (0x80020006)

Tried searching on the error code, but didnt really help me either.

Any help is as always very much appriciated.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 646 posts ]  Go to page Previous  1 ... 14, 15, 16, 17, 18, 19, 20 ... 44  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 10 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