Attaching Excel Sheet

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Attaching Excel Sheet

17 Apr 2019, 06:17

Hello people,
I'm trying to attach an excel sheet, with my script, so that I can have my excel sheet data into clipboard, from which I can use those in a seperate application. I started off like in the following code, but I keep on getting this error "The following variable name contains an illegal character: 'XL.Visible'. The program will exit."
When I tried to make that line as comment, I got another error, saying, "Call to non-existent function" at "ComObjCreate("Excel.Application")". If I try something else, I get an error again at my file path, saying "The leftmost character in the above expression is invalid". So what shall I do to make it work?

Thanks in advance

This is my script.

Code: Select all


Path := "%A_Desktop%\Data\Input.xlsx"
XL := ComObjCreate("Excel.Application")
XL.Workbooks.Open(Path)
XL.Visible := True

User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Attaching Excel Sheet

17 Apr 2019, 06:36

Indhu wrote:
17 Apr 2019, 06:17
Hello people,
I'm trying to attach an excel sheet, with my script, so that I can have my excel sheet data into clipboard, from which I can use those in a seperate application. I started off like in the following code, but I keep on getting this error "The following variable name contains an illegal character: 'XL.Visible'. The program will exit."
When I tried to make that line as comment, I got another error, saying, "Call to non-existent function" at "ComObjCreate("Excel.Application")". If I try something else, I get an error again at my file path, saying "The leftmost character in the above expression is invalid". So what shall I do to make it work?

Thanks in advance

This is my script.

Code: Select all


Path := "%A_Desktop%\Data\Input.xlsx"
XL := ComObjCreate("Excel.Application")
XL.Workbooks.Open(Path)
XL.Visible := True

You are combining Expression and Legacy Syntax (please read this AHK docs page). When using Excel COM, I would try to exclusively stick to Expression syntax, if possible.

try this:

Code: Select all


Path := A_Desktop "\Data\Input.xlsx"
XL := ComObjCreate("Excel.Application")
XL.Workbooks.Open(Path)
XL.Visible := True

-TL
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

17 Apr 2019, 06:56

@Tigerlily

Hello TL, tried your way. Still the same error with file path, " The leftmost character above is illegal in an expression".
-I :)
gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: Attaching Excel Sheet

17 Apr 2019, 10:38

Please show your updated code that causes this error message.
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

19 Apr 2019, 00:12

This was my code, after the above suggesstion

Code: Select all


Path := A_Desktop"\Data\Input.xlsx"
XL := ComObjCreate("Excel.Application")
XL.Workbooks.Open(Path)
XL.Visible := True


-I :)
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Attaching Excel Sheet

19 Apr 2019, 03:07

Try adding a space after A_Desktop, works for me that way.
Good luck!
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

19 Apr 2019, 04:12

Nope..Still shows 'XL.Visible' contains illegal character. :( @AviationGuy
-I :)
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Attaching Excel Sheet

19 Apr 2019, 05:28

The script is running here. My input.xlsx was an empty excel sheet. Probably there is a problem with the file. Replace it of a test.
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

19 Apr 2019, 05:49

@Kobaltauge

The same error again :( . Is there any issue with 'XL.Visible'?
-I :)
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

19 Apr 2019, 05:56

This is the error message I get everytime
@Kobaltauge
ER.PNG
ER.PNG (16.56 KiB) Viewed 2844 times
-I :)
gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: Attaching Excel Sheet

19 Apr 2019, 09:10

Perhaps you copy/pasted an invisible character from somewhere into your script. Try to delete the line and type it again by hand...

Edit: Which AHK version are you using (and which bitness? ANSI/Unicode?) ?
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Attaching Excel Sheet

19 Apr 2019, 09:34

Strange, it should work this way. Try @gregster's suggestion, maybe this is the case.
Also, what do you have on top of your script, since this is line 6...?
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

22 Apr 2019, 00:27

This is how I started my code. I have only declared a hotkey at the top of my script.

My AHK version is: 1.0.48.05, 32 bit, and ANSI encoding.
-I :)
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Attaching Excel Sheet

22 Apr 2019, 01:55

error at line 6
but the script you posted has only 4 lines.
please post the complete script.
It is not much code. Retye it in notelpad. I think somes strange characters are in your .ahk
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

22 Apr 2019, 02:11

This is my script.

Code: Select all

a::

Path := A_Desktop "\Data\Input.xlsx" 
XL := ComObjCreate("Excel.Application")
XL.Workbooks.Open(Path)
XL.Visible := True
Still the same error with a new notepad file.
-I :)
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Attaching Excel Sheet

22 Apr 2019, 03:35

Indhu wrote:
22 Apr 2019, 02:11
This is my script.

Code: Select all

a::

Path := A_Desktop "\Data\Input.xlsx" 
XL := ComObjCreate("Excel.Application")
XL.Workbooks.Open(Path)
XL.Visible := True
Still the same error with a new notepad file.
Does this work?

Code: Select all

Path := A_Desktop "\Data\Input.xlsx" 
Run, % Path
Does this work?

Code: Select all

excel:=ComObjCreate("Excel.Application")
excel.Workbooks.Add
excel.Visible:=true
What do you mean a new notepad file? Are you trying to open a .txt file?
-TL
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

22 Apr 2019, 04:17

Code: Select all

Path := A_Desktop "\Data\Input.xlsx" 
Run, % Path
This works fine.

Code: Select all

excel:=ComObjCreate("Excel.Application")
excel.Workbooks.Add
excel.Visible:=true
This one shows the same error at 'excel.Visible'
What do you mean a new notepad file? Are you trying to open a .txt file?
No. I retyped the code in a new notepad and tried again.

@TigerLily
-I :)
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Attaching Excel Sheet

22 Apr 2019, 05:28

This is very strange. Did you take a look at the log?
Right mouse button on the AHK Icon next to the clock an "open".
Mine looks like this.

Code: Select all

Script lines most recently executed (oldest first).  Press [F5] to refresh.  The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0).  The bottommost line's elapsed time is the number of seconds since it executed.

---- D:\Programmier\autohotkey\AHK-Studio\*
003: SendMode,Input
004: SetWorkingDir,%A_ScriptDir%
006: Return (3.09)
008: Path := A_Desktop "\Data\Input.xlsx"
009: XL := ComObjCreate("Excel.Application") (0.95)
010: XL.Workbooks.Open(Path)   (0.47)
011: XL.Visible := True   (0.23)
013: {
018: Exit (15.59)

Press [F5] to refresh.
Indhu
Posts: 14
Joined: 17 Apr 2019, 05:43

Re: Attaching Excel Sheet

22 Apr 2019, 06:52

@Kobaltauge

I'm not able to open up the log due to this error. I don't get the AHK icon next to the clock, whenever I get an error. I can open the log for other AHK scripts.

Moreover, which ever example codes I try from internet, I always get the same error at " XL.Visible" line, saying it has got an illegal character.

A solution for this will be of major help for me
-I :)
User avatar
Datapoint
Posts: 296
Joined: 18 Mar 2018, 17:06

Re: Attaching Excel Sheet

22 Apr 2019, 08:38

Indhu wrote:
22 Apr 2019, 00:27
My AHK version is: 1.0.48.05, 32 bit, and ANSI encoding.
That's AHK "Basic" / "Classic". It doesn't have objects or COM etc. You need a newer version to use COM. (or use the old COM standard library with that version. Upgrade to AHK 1.1+ if possible)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 196 guests