MkDir Simply Not Creating Folders

C

crferguson

I know this will sound odd, but the MkDir function isn't creating
folders... and it isn't throwing any errors.

I don't have any "On Error Resume Next" anywhere in my code. It just
isn't creating any folders. The folder doesn't already exist and it
isn't trying to create multi-level folder structures or anything like
that. I just want to create a folder named "test" on my root drive
(C:\ in this case). Here's the code:

Private Sub CreateFolder()

sProfileName = "C:\test"
'On Error GoTo folderexists
MkDir sPath & sProfileName
'Exit Sub

'folderexists:
'Exit Sub
End Sub
 
C

crferguson

Sorry, this new interface on Google Groups just posted on it's own...
anyway...

Notice I've commented out the error handling to try and force an error.
sProfileName is a string, of course, and sPath is empty on purpose for
testing. I just want to create a "test" folder on the C drive and it's
not working, causing an error, or anything.

Any help is hugely appreciated!!

Cory
 
C

Chip Pearson

Does the sProfileName contain a leading backslash? You may need to change

MkDir sPath & sProfileName

to

MkDir sPath & "\" & sProfileName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
P

PCLIVE

I'm not sure why it's not working for you. Your code works for me. Are you
able to manually create a folder through Windows Explorer? If you run this
code twice in a row, will it give you an error? Just in case, refresh
Windows Explorer (F5).

Regards,
Paul
 
C

Chip Pearson

I misread your post, but your code is all screwed up.

This
sProfileName = "C:\test" combined with
MkDir sPath & sProfileName

looks backwards. You should have

sPath = "C:\Test"
and sProfileName contains a subfolder name, and then use code like

MkDir sPath & "\" & sProfileName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
C

Chip Pearson

Ron,

I haven't installed Vista yet. Is there an issue with MkDir?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
R

Ron de Bruin

Hi Chip

Vista have protected parts of the hard disk.
Maybe there is no permission for C:\

I not test the MKdir on C but if you want to save a file on C you will see a permission dialog.

With this text

"You don't have permission to save in this location"
"Would you like to save in the Documents folder instead?"

But maybe creating a folder with code is no problem?
I check it out this evening
 
R

Ron de Bruin

Creating a folder in C:\ is no problem Chip in Vista
Only saving your test macros with code in C:\ because the path is short<g> is not possible
in Vista anymore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top