PC Review


Reply
Thread Tools Rate Thread

Auto_open to check for folder

 
 
=?Utf-8?B?T2xkamF5?=
Guest
Posts: n/a
 
      12th Aug 2007
I want my Auto_open file to check to see if there is a folder and if not
create it
Something like
user = Application.username
If "//server3/jobs/user/" exists then
do something
Else
create the user folder
 
Reply With Quote
 
 
 
 
Mark Ivey
Guest
Posts: n/a
 
      12th Aug 2007
Jay,

Steve Yandl posted a solution for part of your problem (please scroll down
below this post to see his message).

To alter what he had a bit and get to what you were wanting, give this a
try:

In your Personal.xls workbook, put this code into "ThisWorkbook"

Private Sub Workbook_Open()
user = Application.UserName

Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("\\server3\jobs\" & user)
strUserFolder = objFolder.Self.Path

If fso.FolderExists(strUserFolder & "\" & user) Then
'Do something
MsgBox "The folder already exists"
ElseIf Not fso.FolderExists(strUserFolder & "\" & user) Then
Set fldr = fso.CreateFolder(strUserFolder & "\" & user)
End If

Set objShell = Nothing
Set fso = Nothing

End Sub

***********************************************************
*************** Original Post from Steve Yandl *******************
***********************************************************

"Steve Yandl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Bob,
>
> Just read your question again and see you also wanted to create the
> folder. Try this.
>
> _____________________________
>
> Sub FolderToDesk()
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("Shell.Application")
> Set objFolder = objShell.Namespace(&H10&)
> strMyDesk = objFolder.Self.Path
>
> If Not fso.FolderExists(strMyDesk & "\BlankFolder") Then
> Set fldr = fso.CreateFolder(strMyDesk & "\BlankFolder")
> End If
>
> Set objShell = Nothing
> Set fso = Nothing
> End Sub
> ______________________________
>
> Steve



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      12th Aug 2007
One way to check to see if a folder exists:

Option Explicit
Sub Auto_Open()

Dim TestStr As String
Dim FolderName As String

FolderName = "\\server3\jobs\" & application.username

If Right(FolderName, 1) <> "\" Then
FolderName = FolderName & "\"
End If

TestStr = ""
On Error Resume Next
TestStr = Dir(FolderName & "nul")
On Error GoTo 0

If TestStr = "" Then
MsgBox FolderName & " not found"
Else
MsgBox FolderName & " was found"
End If

End Sub

Another way is go use File System Object.

Option Explicit
Sub Auto_Open()
Dim FSO As Object
Dim FolderName As String

FolderName = "\\server3\jobs\" & Application.UserName

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(FolderName) = False Then
MsgBox FolderName & " not found"
Else
MsgBox FolderName & " was found"
End If
End Sub



Oldjay wrote:
>
> I want my Auto_open file to check to see if there is a folder and if not
> create it
> Something like
> user = Application.username
> If "//server3/jobs/user/" exists then
> do something
> Else
> create the user folder


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?T2xkamF5?=
Guest
Posts: n/a
 
      12th Aug 2007
What I am attempting to is when a new user (not on my machine) opens this
Workbook it will add his personal folder to the server. Will your routine
work under this condition?

oldjay
"Mark Ivey" wrote:

> Jay,
>
> Steve Yandl posted a solution for part of your problem (please scroll down
> below this post to see his message).
>
> To alter what he had a bit and get to what you were wanting, give this a
> try:
>
> In your Personal.xls workbook, put this code into "ThisWorkbook"
>
> Private Sub Workbook_Open()
> user = Application.UserName
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("Shell.Application")
> Set objFolder = objShell.Namespace("\\server3\jobs\" & user)
> strUserFolder = objFolder.Self.Path
>
> If fso.FolderExists(strUserFolder & "\" & user) Then
> 'Do something
> MsgBox "The folder already exists"
> ElseIf Not fso.FolderExists(strUserFolder & "\" & user) Then
> Set fldr = fso.CreateFolder(strUserFolder & "\" & user)
> End If
>
> Set objShell = Nothing
> Set fso = Nothing
>
> End Sub
>
> ***********************************************************
> *************** Original Post from Steve Yandl *******************
> ***********************************************************
>
> "Steve Yandl" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Bob,
> >
> > Just read your question again and see you also wanted to create the
> > folder. Try this.
> >
> > _____________________________
> >
> > Sub FolderToDesk()
> > Set fso = CreateObject("Scripting.FileSystemObject")
> > Set objShell = CreateObject("Shell.Application")
> > Set objFolder = objShell.Namespace(&H10&)
> > strMyDesk = objFolder.Self.Path
> >
> > If Not fso.FolderExists(strMyDesk & "\BlankFolder") Then
> > Set fldr = fso.CreateFolder(strMyDesk & "\BlankFolder")
> > End If
> >
> > Set objShell = Nothing
> > Set fso = Nothing
> > End Sub
> > ______________________________
> >
> > Steve

>
>
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      12th Aug 2007
> One way to check to see if a folder exists:
>
> Option Explicit
> Sub Auto_Open()
>
> Dim TestStr As String
> Dim FolderName As String
>
> FolderName = "\\server3\jobs\" & application.username
>
> If Right(FolderName, 1) <> "\" Then
> FolderName = FolderName & "\"
> End If
>
> TestStr = ""
> On Error Resume Next
> TestStr = Dir(FolderName & "nul")
> On Error GoTo 0
>
> If TestStr = "" Then
> MsgBox FolderName & " not found"
> Else
> MsgBox FolderName & " was found"
> End If
>
> End Sub
>
> Another way is go use File System Object.
>
> Option Explicit
> Sub Auto_Open()
> Dim FSO As Object
> Dim FolderName As String
>
> FolderName = "\\server3\jobs\" & Application.UserName
>
> Set FSO = CreateObject("Scripting.FileSystemObject")
>
> If FSO.FolderExists(FolderName) = False Then
> MsgBox FolderName & " not found"
> Else
> MsgBox FolderName & " was found"
> End If
> End Sub


And here is yet another way to see if a folder exists...

Private Function FolderExists(PathName As String) As Boolean
On Error Resume Next
If Len(PathName) > 0 Then
FolderExists = ((GetAttr(PathName) And vbDirectory) > 0)
Err.Clear
End If
End Function

Here is the companion file exists funciton...

Private Function FileExists(FileName As String) As Boolean
On Error Resume Next
If Len(FileName) > 0 Then
FileExists = ((GetAttr(FileName) And vbDirectory) = 0)
Err.Clear
End If
End Function

Rick
 
Reply With Quote
 
Mark Ivey
Guest
Posts: n/a
 
      12th Aug 2007
Ahhh...

Yes this same procedure should work. Just place it in the "ThisWorkbook"
section of the active workbook and it should perform the same thing, except
for that workbook only...


Mark Ivey


"Oldjay" <(E-Mail Removed)> wrote in message
news:B152ABCE-B27A-42C3-84CD-(E-Mail Removed)...
> What I am attempting to is when a new user (not on my machine) opens this
> Workbook it will add his personal folder to the server. Will your routine
> work under this condition?
>
> oldjay
> "Mark Ivey" wrote:
>
>> Jay,
>>
>> Steve Yandl posted a solution for part of your problem (please scroll
>> down
>> below this post to see his message).
>>
>> To alter what he had a bit and get to what you were wanting, give this a
>> try:
>>
>> In your Personal.xls workbook, put this code into "ThisWorkbook"
>>
>> Private Sub Workbook_Open()
>> user = Application.UserName
>>
>> Set fso = CreateObject("Scripting.FileSystemObject")
>> Set objShell = CreateObject("Shell.Application")
>> Set objFolder = objShell.Namespace("\\server3\jobs\" & user)
>> strUserFolder = objFolder.Self.Path
>>
>> If fso.FolderExists(strUserFolder & "\" & user) Then
>> 'Do something
>> MsgBox "The folder already exists"
>> ElseIf Not fso.FolderExists(strUserFolder & "\" & user) Then
>> Set fldr = fso.CreateFolder(strUserFolder & "\" & user)
>> End If
>>
>> Set objShell = Nothing
>> Set fso = Nothing
>>
>> End Sub
>>
>> ***********************************************************
>> *************** Original Post from Steve Yandl *******************
>> ***********************************************************
>>
>> "Steve Yandl" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Bob,
>> >
>> > Just read your question again and see you also wanted to create the
>> > folder. Try this.
>> >
>> > _____________________________
>> >
>> > Sub FolderToDesk()
>> > Set fso = CreateObject("Scripting.FileSystemObject")
>> > Set objShell = CreateObject("Shell.Application")
>> > Set objFolder = objShell.Namespace(&H10&)
>> > strMyDesk = objFolder.Self.Path
>> >
>> > If Not fso.FolderExists(strMyDesk & "\BlankFolder") Then
>> > Set fldr = fso.CreateFolder(strMyDesk & "\BlankFolder")
>> > End If
>> >
>> > Set objShell = Nothing
>> > Set fso = Nothing
>> > End Sub
>> > ______________________________
>> >
>> > Steve

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for the existence of the Temporary folder namedTemporary Folder a , 2 and so on before deleting as the name is not fixed Yuvraj Microsoft Excel Programming 1 3rd May 2009 09:41 PM
Re: Auto_Open Check date and Close DLS Microsoft Excel Programming 2 5th Aug 2003 05:28 AM
Re: Auto_Open Check date and Close Tom Ogilvy Microsoft Excel Programming 0 3rd Aug 2003 03:54 AM
Re: Auto_Open Check date and Close Dan Smith Microsoft Excel Programming 0 2nd Aug 2003 10:39 PM
Auto_Open Check date and Close DLS Microsoft Excel Programming 1 1st Aug 2003 09:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 AM.