Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Using Wildcards for Folders

Excel 2003

The following is stored in my PERSONAL.xls file.

I have a module with a series of macros. One of them is a Private Sub that
checks the path of the current workbook and, if the path of the current
workbook doesn't check out with what I have written, the user will get a
warning and the macro will not run. All other macros are public so I can call
them up with the Macros button, and their first line is to Call Directory
(Directory being the name of the Private Sub with the ActiveWorkbook.Path
line). The last folder of the path is a year. As opposed to manually changing
the name of the last folder every year, can I use a wildcard (*) to make it
accept any folder like 20* for the years? The only reason I am asking is that
my boss has this macro in her PERSONAL.xls (which I set up for her) and the
project is locked. Here's an example:

Change:
O:\Folder1\2008
to
O:\Folder1\20*

The reason for the Directory sub is that the macros are tailored to certain
files with the same setup, so it wouldn't work otherwise. Thanks in advance.
--
Please rate posts so we know when we have answered your questions. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default Using Wildcards for Folders

Hi

You could use something like the following
Dim spath As String, lpos As Long

spath = Thisworkbook.Path
lpos = InStrRev(spath, "\")
If Mid(spath, lpos + 1, 2) < "20" Then
MsgBox "Wrong Folder"
End If


--
Regards
Roger Govier

"Orion Cochrane" wrote in message
...
Excel 2003

The following is stored in my PERSONAL.xls file.

I have a module with a series of macros. One of them is a Private Sub that
checks the path of the current workbook and, if the path of the current
workbook doesn't check out with what I have written, the user will get a
warning and the macro will not run. All other macros are public so I can
call
them up with the Macros button, and their first line is to Call Directory
(Directory being the name of the Private Sub with the ActiveWorkbook.Path
line). The last folder of the path is a year. As opposed to manually
changing
the name of the last folder every year, can I use a wildcard (*) to make
it
accept any folder like 20* for the years? The only reason I am asking is
that
my boss has this macro in her PERSONAL.xls (which I set up for her) and
the
project is locked. Here's an example:

Change:
O:\Folder1\2008
to
O:\Folder1\20*

The reason for the Directory sub is that the macros are tailored to
certain
files with the same setup, so it wouldn't work otherwise. Thanks in
advance.
--
Please rate posts so we know when we have answered your questions. Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Using Wildcards for Folders

Here is the code for Directory:
Private Sub Directory()
'Checks filepath
If ActiveWorkbook.Path = "C:\Folder1\[Folder2] - 2008" Or _
ActiveWorkbook.Path = "C:\Folder1\[Folder3] - 2008" Then
Application.Run (Macro)
Else
MsgBox [msg]
End
End If
End Sub

Where

[Folder1] is the first folder in the drive
[Folder2] is a sub-folder within [Folder1] that has 4 characters and then
the " - 2008"
[Folder3] is a sub-folder within [Folder1] that has 10 characters and then
the " - 2008"

[Folder2] and [Folder3] do not contain spaces before the " - 2008" suffix.

I tried what you said and it didn't work. I wasn't too clear as to the
format of the current folder name. Can you modify your code so I can use it?
Thanks.
--
Please rate posts so we know when we have answered your questions. Thanks.


"Roger Govier" wrote:

Hi

You could use something like the following
Dim spath As String, lpos As Long

spath = Thisworkbook.Path
lpos = InStrRev(spath, "\")
If Mid(spath, lpos + 1, 2) < "20" Then
MsgBox "Wrong Folder"
End If


--
Regards
Roger Govier

"Orion Cochrane" wrote in message
...
Excel 2003

The following is stored in my PERSONAL.xls file.

I have a module with a series of macros. One of them is a Private Sub that
checks the path of the current workbook and, if the path of the current
workbook doesn't check out with what I have written, the user will get a
warning and the macro will not run. All other macros are public so I can
call
them up with the Macros button, and their first line is to Call Directory
(Directory being the name of the Private Sub with the ActiveWorkbook.Path
line). The last folder of the path is a year. As opposed to manually
changing
the name of the last folder every year, can I use a wildcard (*) to make
it
accept any folder like 20* for the years? The only reason I am asking is
that
my boss has this macro in her PERSONAL.xls (which I set up for her) and
the
project is locked. Here's an example:

Change:
O:\Folder1\2008
to
O:\Folder1\20*

The reason for the Directory sub is that the macros are tailored to
certain
files with the same setup, so it wouldn't work otherwise. Thanks in
advance.
--
Please rate posts so we know when we have answered your questions. 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
List folders but not sub folders kaiser Excel Programming 2 July 19th 07 11:14 AM
Wildcards and if Arlene Excel Worksheet Functions 3 June 21st 07 12:05 AM
Wildcards italiavb Excel Programming 0 July 14th 06 01:22 AM
Wildcards in VBA oodam Excel Programming 6 June 19th 06 07:03 PM
Wildcards HELP ME PLEASE! Excel Programming 3 December 3rd 03 01:22 PM


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