windows.namefile.activate


Posted by amroo on April 24, 2001 12:00 AM

Bonjour,
I wrote this code but an error message said that it's wrong.

namefile = InputBox("enter the name file to import")
'here the error is.
Windows("namefile.txt").Activate

I try a lot of combinaisons
("namefile".txt), ((namefile).txt), ("(namefile).txt")
and so others but it still bugging.
Thank you for the help.
amroo

Posted by Dave Hawley on April 24, 2001 12:10 AM

Hi amroo

Two things here. Is the file that they type in open already ? If not the .Activate will not work. If it is not open and you do want to open it, use the GetOpenFileName dialog, rather than a Inputbox. They cannot mistype any names then.

Sub tryThis()
Dim namefile As String
namefile = Application.GetOpenFilename
If namefile = False Then Exit Sub
Workbooks.Open namefile
End Sub


.....If the file is open then use this syntax:

Sub OrThis()
Dim namefile As String
namefile = InputBox("enter the name file to import")
If namefile = "" Then Exit Sub
Windows(namefile & ".txt").Activate

End Sub


But personally I would not have enough faith in users to type the name of a file you want them to Activate. I would fill a Listbox or Combobox myself.

Dave


OzGrid Business Applications

Posted by Ivan Moala on April 24, 2001 7:05 AM

.....If the file is open then use this syntax: namefile = InputBox("enter the name file to import") If namefile = "" Then Exit Sub Windows(namefile & ".txt").Activate But personally I would not have enough faith in users to type the name of a file you want them to Activate. I would fill a Listbox or Combobox myself. Dave

Dave, agree with you....don't let users type in
anything.....give them options.
Just one other point;
the False should be "False" string and not Boolean
in the routine trythis.

Ivan


Posted by Jerid on April 24, 2001 7:21 AM


The code will work with False (Boolean) OR "False" (String)

Jerid

Posted by Ivan Moala on April 24, 2001 8:52 AM

Jerid
Have you tried it by selecting a file name ?
On cancel it works.

Ivan



Posted by Jerid on April 24, 2001 9:27 AM

Ivan

Sorry, I forgot one key piece of info. You need to change the filename variable to a variant.

Jerid