Variable Excel Sheet Name Error

Get help with using AutoHotkey and its commands and hotkeys
User avatar
SirSocks
Posts: 50
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: 609
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: 193
Joined: 29 Sep 2013, 19:01
Location: Burbank, California

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

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], ineuw, reluct, swagfag and 168 guests