Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Checking for the Existence of a Folder

I need to check the folder "c:\program files\microsoft
office" to see if a folder that is inside this folder is
named office or office10 (or office something depending
on the version of office that is installed on a PC) and
run code based on the name of the folder. I have been
attempting to use the dir function as follows: zx=dir
("c:\program files\microsoft office\office*") but this
only returns a zero string, even though a folder
beginining with the work office is in there. What code
would I need to use to check for the existence of a
folder whose name always contains office but could
contain other characters as well? Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Checking for the Existence of a Folder

Hi Viswanath Tumu,

Viswanath Tumu wrote:
I need to check the folder "c:\program files\microsoft
office" to see if a folder that is inside this folder is
named office or office10 (or office something depending
on the version of office that is installed on a PC) and
run code based on the name of the folder. I have been
attempting to use the dir function as follows: zx=dir
("c:\program files\microsoft office\office*") but this
only returns a zero string, even though a folder
beginining with the work office is in there. What code
would I need to use to check for the existence of a
folder whose name always contains office but could
contain other characters as well? Thanks!


try this:

Sub FileDir()
Dim strPath As String
Dim zx As String
Dim objFSO As Object
Dim objSubFolder As Object

strPath = "c:\program files\microsoft office\"
Set objFSO = CreateObject("Scripting.FileSystemObject")

If Dir(strPath & "Office*", vbDirectory) < "" Then
For Each objSubFolder In objFSO.GetFolder(strPath).SubFolders
If InStr(objSubFolder.Name, "Office") Then
zx = objSubFolder.Name
Exit For
End If
Next objSubFolder

MsgBox zx
End If
End Sub

Another idea is to have a look at the Version from the Application:

Sub AppVersion()
Dim zx As String
zx = "Office" & IIf(Val(Application.Version) 9, _
" " & Val(Application.Version), "")
End Sub


--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Checking for the Existence of a Folder

Hi Viswanath,

Here is a simple function to do it

Function FolderExists(Folder) As Boolean
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
FolderExists = True
End If
End If
End Function

use like

Debug.Print FolderExists("c:\program files\microsoft office")

or even

Debug.Print FolderExists("c:\program files\* office")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Viswanath Tumu" wrote in message
...
I need to check the folder "c:\program files\microsoft
office" to see if a folder that is inside this folder is
named office or office10 (or office something depending
on the version of office that is installed on a PC) and
run code based on the name of the folder. I have been
attempting to use the dir function as follows: zx=dir
("c:\program files\microsoft office\office*") but this
only returns a zero string, even though a folder
beginining with the work office is in there. What code
would I need to use to check for the existence of a
folder whose name always contains office but could
contain other characters as well? Thanks!



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
Checking for the existence of a worksheet Allen Excel Discussion (Misc queries) 1 January 20th 10 06:57 PM
Spell Checking with checking cell notes jfitzpat Excel Discussion (Misc queries) 0 August 8th 07 10:26 PM
Checking for the existence of a characted in a string Peter Rooney Excel Discussion (Misc queries) 2 June 21st 06 10:16 AM
Checking to see if Folder exists Dan[_25_] Excel Programming 2 September 24th 03 02:42 AM
Checking for existence of macros or code in an Excel Spreadsheet Youssef Mourra Excel Programming 3 August 13th 03 05:13 PM


All times are GMT +1. The time now is 03:20 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"