ComObjGet Bad Extension Error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

ComObjGet Bad Extension Error

02 Oct 2015, 14:01

Hey All! I'm finished beating my head against the proverbial wall, I simply can't rat out the source of this error!!!
I have a set of 6 text files, and I want my script to randomly select one of them, so I generate a random number between 1 and 6, then append the file address with that number and the extension ".txt," and then then use COM Object Get to retrieve the contents of said file, and then paste it's content.
But it keeps giving me an error saying "Bad Extension for File," And I cannot for the life of me figure out what's causing the problem! Extensions are visible in Explorer, and I've quintuple checked to make sure it's typed correctly.

Here's my code:

Code: Select all

#j::
Random, BodyNumber, 1,6
Msgbox, %BodyNumber% ;For Debug
SelectedRandomBody := "S:\Recruiting\Advertising\Automation\Bodies\Body" . BodyNumber . ".txt"
Msgbox,,Random Body Variable, %SelectedRandomBody% ;For Debug
oDoc := ComObjGet(SelectedRandomBody).Range.FormattedText.Copy
Send, ^v
return
farfaraway
Posts: 15
Joined: 02 Oct 2015, 15:18

Re: ComObjGet Bad Extension Error

02 Oct 2015, 15:27

I don't think txt files have COM support. That oDoc line there is for working with doc(x) files. Does this work for you?

Code: Select all

#j::
Random, BodyNumber, 1,6
Msgbox, %BodyNumber% ;For Debug
SelectedRandomBody := "S:\Recruiting\Advertising\Automation\Bodies\Body" . BodyNumber . ".txt"
Msgbox,,Random Body Variable, %SelectedRandomBody% ;For Debug
FileRead, OutputVar, %SelectedRandomBody%
Msgbox % OutputVar
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 350 guests