Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to activate a file when the filename is represented by a string variable

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default How to activate a file when the filename is represented by a string variable

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to activate a file when the filename is represented by a string variable

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


"Jan Karel Pieterse" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default How to activate a file when the filename is represented by a string variable

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to activate a file when the filename is represented by a string variable

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

--
Regards,
Tom Ogilvy


"news.sintef.no" wrote in message
...
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


"Jan Karel Pieterse" wrote in message
...
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a string variable as the file name [email protected] Excel Discussion (Misc queries) 1 March 28th 07 11:10 PM
Nested String Filename Variable ed9213 Excel Worksheet Functions 9 February 12th 07 02:27 AM
Macro to open most recent file with a particular filename string kwiklearner Excel Discussion (Misc queries) 1 August 23rd 06 01:24 AM
Put Filename Variable in Macro David Excel Discussion (Misc queries) 4 December 27th 05 06:27 PM
Using a variable string in a file save path Ron[_13_] Excel Programming 1 October 16th 03 08:29 PM


All times are GMT +1. The time now is 12:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"