Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Open folder with code

I need a coding solution to the following: I have a command button on a sheet
which is to open a Windows Explorer Directory. I have previously used
hyperlinks to open and show the user with the following code (with button).

Range("V8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("A1").Select
Application.ScreenUpdating = False

I was wondering if there is a better way to do without having the hyperlink.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Open folder with code

Damien,
Here's one way:
Private Sub CommandButton2_Click()
Dim SysRoot As String
SysRoot = Split(Environ(20), "=")(1)
Shell SysRoot & "\explorer.exe /e, G:", vbNormalFocus
End Sub

NickHK

"Damien" wrote in message
...
I need a coding solution to the following: I have a command button on a

sheet
which is to open a Windows Explorer Directory. I have previously used
hyperlinks to open and show the user with the following code (with

button).

Range("V8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("A1").Select
Application.ScreenUpdating = False

I was wondering if there is a better way to do without having the

hyperlink.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Open folder with code

Thanks Nick, I will try it out, I suppose my other alternative is to
dynamically change the hyperlink via a selection value from a combo box. My
reasoning is that the user may wish to see a particular file belonging to a
project name located in the combo box. Is that at all possible?

Cheers

"NickHK" wrote:

Damien,
Here's one way:
Private Sub CommandButton2_Click()
Dim SysRoot As String
SysRoot = Split(Environ(20), "=")(1)
Shell SysRoot & "\explorer.exe /e, G:", vbNormalFocus
End Sub

NickHK

"Damien" wrote in message
...
I need a coding solution to the following: I have a command button on a

sheet
which is to open a Windows Explorer Directory. I have previously used
hyperlinks to open and show the user with the following code (with

button).

Range("V8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("A1").Select
Application.ScreenUpdating = False

I was wondering if there is a better way to do without having the

hyperlink.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Open folder with code

Damien,
Just build the shell string from a variable or range value. e.g.

Private Sub CommandButton2_Click()
Dim SysRoot As String
Dim FilePath as String

SysRoot = Split(Environ(20), "=")(1)
FilePath = Range("a1").Text 'Or cboFile.Text
'Assumes FilePath is the full path to the file
Shell SysRoot & "\explorer.exe /e, " & FilePath, vbNormalFocus
End Sub

You should add some error trapping and/or checking that FilePath is valid.

NickHK

"Damien" wrote in message
...
Thanks Nick, I will try it out, I suppose my other alternative is to
dynamically change the hyperlink via a selection value from a combo box.

My
reasoning is that the user may wish to see a particular file belonging to

a
project name located in the combo box. Is that at all possible?

Cheers

"NickHK" wrote:

Damien,
Here's one way:
Private Sub CommandButton2_Click()
Dim SysRoot As String
SysRoot = Split(Environ(20), "=")(1)
Shell SysRoot & "\explorer.exe /e, G:", vbNormalFocus
End Sub

NickHK

"Damien" wrote in message
...
I need a coding solution to the following: I have a command button on

a
sheet
which is to open a Windows Explorer Directory. I have previously used
hyperlinks to open and show the user with the following code (with

button).

Range("V8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("A1").Select
Application.ScreenUpdating = False

I was wondering if there is a better way to do without having the

hyperlink.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Open folder with code

SysRoot = Split(Environ(20), "=")(1)

You can't rely on the system root folder being the 20th item in
the Environment variables. On my machine, Environ(20) is the
Processor Identifier. Instead, use

SysRoot = Environ("SystemRoot")



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"NickHK" wrote in message
...
Damien,
Here's one way:
Private Sub CommandButton2_Click()
Dim SysRoot As String
SysRoot = Split(Environ(20), "=")(1)
Shell SysRoot & "\explorer.exe /e, G:", vbNormalFocus
End Sub

NickHK

"Damien" wrote in message
...
I need a coding solution to the following: I have a command
button on a

sheet
which is to open a Windows Explorer Directory. I have
previously used
hyperlinks to open and show the user with the following code
(with

button).

Range("V8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False,
AddHistory:=True
Range("A1").Select
Application.ScreenUpdating = False

I was wondering if there is a better way to do without having
the

hyperlink.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Open folder with code

Chip you are sheer genius. SysRoot = Environ("SystemRoot") done the trick
perfectly, Cheers Guys, D.

"Chip Pearson" wrote:

SysRoot = Split(Environ(20), "=")(1)


You can't rely on the system root folder being the 20th item in
the Environment variables. On my machine, Environ(20) is the
Processor Identifier. Instead, use

SysRoot = Environ("SystemRoot")



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"NickHK" wrote in message
...
Damien,
Here's one way:
Private Sub CommandButton2_Click()
Dim SysRoot As String
SysRoot = Split(Environ(20), "=")(1)
Shell SysRoot & "\explorer.exe /e, G:", vbNormalFocus
End Sub

NickHK

"Damien" wrote in message
...
I need a coding solution to the following: I have a command
button on a

sheet
which is to open a Windows Explorer Directory. I have
previously used
hyperlinks to open and show the user with the following code
(with

button).

Range("V8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False,
AddHistory:=True
Range("A1").Select
Application.ScreenUpdating = False

I was wondering if there is a better way to do without having
the

hyperlink.





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
Help: Can open a spreadsheet in a folder which contains spaces in the folder name! 1tsols Excel Programming 17 July 31st 06 04:26 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
open folder _open file code? Ella[_2_] Excel Programming 0 September 12th 05 06:17 PM
open file from folder save in new folder tim64[_3_] Excel Programming 20 June 17th 05 07:58 PM
Open Folder - Ogilvy code No Name Excel Programming 5 August 14th 04 01:19 AM


All times are GMT +1. The time now is 01:29 PM.

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"