How to activate a file when the filename is represented by a string variable

  • Thread starter Thread starter news.sintef.no
  • Start date Start date
N

news.sintef.no

How do I activate a file when the filename is a string variable retrieved by
the "Application.GetOpenFilename" command?

strFilnavn = Application.GetOpenFilename("NPR-uttrekk (*.txt; *.org;
*.dat; *.raw),*.txt;*.org;*.dat;*.raw")
Windows("Another filename").Activate
Windows(strFileName).Activate

My problem is that "windows.activate" command don't accept a string
variable.

Is there another way (assigning a "current open file" number for this file?)
to activate the "strFileName" file?

Thanks for any suggestions

Frank
 
Hi News.sintef.no,
How do I activate a file when the filename is a string variable retrieved by
the "Application.GetOpenFilename" command?

strFilnavn = Application.GetOpenFilename("NPR-uttrekk (*.txt; *.org;
*.dat; *.raw),*.txt;*.org;*.dat;*.raw")

The getopenfilename method does not open the file, it merely gets the name
from the user (or an empty string on a cancel).

So you need to use

Workbooks.Open strFilnavn

first.

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 
OK, but how do I activate from a macro, a file that is already opened but
not currently activated (in focus)?

My problem is that the windows.activate method don't accept a file name
referenced by a string variable.

Frank
 
Hi News.sintef.no,
OK, but how do I activate from a macro, a file that is already opened but
not currently activated (in focus)?

My problem is that the windows.activate method don't accept a file name
referenced by a string variable.

Something like this:

Dim oWkbk as Workbook
Set oWkbk=Workbooks.Open(strFilename)

Later on:

Windows(owkbk.Name).Activate

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 
strFilnavn = Application.GetOpenFilename( _
"NPR-uttrekk (*.txt; *.org; *.dat; *.raw),*.txt;*.org;*.dat;*.raw")
set wkbk = workbooks.Open(strFilnavn)
' optional
sName = wkbk.Name ' sName will be like "Myworkbook.xls"

' later

wkbk.Activate
' or workbooks(sName).Activate


alterate method

for each wbk in Application.Workbooks
if lcase(strFilnaven) = lcase(wbk.Fullname) then
wkb.Activate
exit for
end if
Next
 
Back
Top