VBA folder names with a period

trichmondcpa

New Member
Joined
Jan 28, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I wrote a little script to create folders based on a cell value. I ran into an issue because I need to create the folders using people's names and there are numerous that have a middle initial and period (that's the way they are formatted in our systems.)

The code below runs fine but what is happening is when it has to save the folder to Smith, Henry A. & Mary B. (the value in the cell) it will drop the final period and name the folder Smith, Henry A. & Mary B (no final period). I would prefer to not have to go in and monkey around with stripping the periods, etc. if there is a convenient way to just have it use the full name already in the cell. I can I guess strip all the periods just curious to learn if there was a better way.

(I erroneously posted about this being a file name issue and have reported my post hoping to have it removed. I apologize for this mistake.)

VBA Code:
strDir = Sheets("Table1").Cells(x + 1, 1).Value
strPath = "G:\Folder Test\"
MkDir strPath & strDir
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
These are characters " * : < > ? \ / | you shouldn't use in folder-names and file-names in a Windows system but . isn't allowed in last position because of rules coming from the old DOS since:
.\ refers to the current directory
..\ refers to the parent directory

So whenever you have something to do with a name with an ending dot you will have to strip it in your table or in the macro:
VBA Code:
strDir = Sheets("Table1").Cells(x + 1, 1).Value
If Right(strDir, 1) = "." Then strDir = Left(strDir, Len(strDir) - 1) '<- added
strPath = "G:\Folder Test\"
MkDir strPath & strDir
There is no better way (only a different way to strip the dot).
 
Last edited:
Upvote 0
Solution

A way 'to strip the dot' is to use another dot you can find within the ascii characters table …​
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top