Variable Excel Sheet Name Error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Variable Excel Sheet Name Error

20 Jun 2019, 10:27

Hello -

Goal: I want to copy a specific range from excel to the clipboard.
Problem: I get an error message saying "The Following variable name contains illegal character"
Question: How can I change this code to avoid the error messages?

Code: Select all

XL := ComObjActive("Excel.Application") ; Creates a handle to excel
vSheetName := %SheetName% ; User select the SheetName from a gui dropdown
clipboard := XL.Sheets(vSheetName).Range("BY14:BZ22") ; Clipboard copies the specific range within the SheetName
All help is appreciated,
Thank you.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: Variable Excel Sheet Name Error

20 Jun 2019, 10:56

Code: Select all

vSheetName :=	SheetName	; <~~ no percent signs around 'SheetName'
User avatar
flyingDman
Posts: 2832
Joined: 29 Sep 2013, 19:01

Re: Variable Excel Sheet Name Error

20 Jun 2019, 11:19

I would use:

Code: Select all

XL.Sheets(vSheetName).Range("a1:c2").copy 					; Clipboard copies the specific range within the SheetName
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Leonardo_Portela and 128 guests