Variable not recognized in Excel application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hidefguy
Posts: 57
Joined: 11 Apr 2017, 20:42

Variable not recognized in Excel application

06 Feb 2018, 16:49

I'm trying to simplify file selection using the following file name variable and getting "Couldn't find file" error. Played around with it , and still same error

FileToName := Perm
xlApp := ComObjActive("Excel.Application")
FileTo_Path := A_Desktop "\%FileToName%.xlsx"
FileTo := xlApp.Workbooks.Open(FileTo_Path)
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Variable not recognized in Excel application

06 Feb 2018, 17:14

A couple of problems (at least). Here are a couple corrections:

Code: Select all

FileToName := "Perm" ; otherwise you're naming it the contents of the variable named Perm, which is probably empty
xlApp := ComObjActive("Excel.Application")
FileTo_Path := A_Desktop "\" FileToName ".xlsx" ; fixed a couple things here
FileTo := xlApp.Workbooks.Open(FileTo_Path)
hidefguy
Posts: 57
Joined: 11 Apr 2017, 20:42

Re: Variable not recognized in Excel application

06 Feb 2018, 20:55

Works great. Thanks again bud
hidefguy
Posts: 57
Joined: 11 Apr 2017, 20:42

Re: Variable not recognized in Excel application

25 Feb 2018, 02:19

Can enter FileToName from an input box like this somehow?

FileToName := "F"
InputBox, F,,Destination file
xlApp := ComObjActive("Excel.Application")
FileTo_Path := A_Desktop "\" FileToName ".xlsx"
FileTo := xlApp.Workbooks.Open(FileTo_Path)
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Variable not recognized in Excel application

25 Feb 2018, 02:27

Get rid of the first line. Doesn't make sense to assign a string "F" to the variable. It seems like you think you're linking it to the variable named F from the next line, but it's not doing anything like that.

In the InputBox command, just replace F with FileToName.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat, ReyAHK and 280 guests