Page 1 of 1

Variable Excel Sheet Name Error

Posted: 20 Jun 2019, 10:27
by SirSocks
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.

Re: Variable Excel Sheet Name Error

Posted: 20 Jun 2019, 10:56
by sinkfaze

Code: Select all

vSheetName :=	SheetName	; <~~ no percent signs around 'SheetName'

Re: Variable Excel Sheet Name Error

Posted: 20 Jun 2019, 11:19
by flyingDman
I would use:

Code: Select all

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