Code Not Compatible with XL2003

Tricky

Board Regular
Joined
Jun 8, 2002
Messages
77
Sub CreateFolders()

path = InputBox(“Enter the path where you want to create the folders”)
cell = InputBox(“First cell”)

Range(cell).Select
Do While ActiveCell.Value <> “”
MkDir (path & “/” & ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
End Sub

I was looking for code that would generate new folders from a selected list on an Excel sheet. I found this code with a quick Google search. I'm sure this code probably works well for most folks, but I'm using Excel 2003 (I know, I know... but I like it). So, this code will not run in 2003, it gets stuck on the red lines. Is there a workaround for this? I found other code that works but it has the Output Directory hardwired. I want to be able to choose the output directory before the code executes. Help with this would be most appreciated.
 

Attachments

  • Capture.JPG
    Capture.JPG
    26.7 KB · Views: 7

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What is meant by : "it gets stuck on the red lines." ?

Be very specific of what happens, what error messages are displayed, how does Excel react ?
 
Upvote 0
I am pretty sure that InputBox's worked back in Excel 2003.
Do you have Option Explicit turned on? If so, you need declare your variables before using them.
And your slash is going the wrong way.

Also, Excel does not like slanted double-quotes. They must be straight ones (").
Rich (BB code):
Sub CreateFolders()

Dim path as String
Dim cell as String

path = InputBox("Enter the path where you want to create the folders")
cell = InputBox("First cell")
Range(cell).Select
Do While ActiveCell.Value <> ""
MkDir (path & "\" & ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
Solution
Not sure if it's from copying the code to here, but all your quotes are wrong, it should be like
VBA Code:
Sub CreateFolders()

Path = InputBox("Enter the path where you want to create the folders")
Cell = InputBox("First cell")
Range(Cell).Select
Do While ActiveCell.Value <> ""
MkDir (Path & "\" & ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
What is meant by : "it gets stuck on the red lines." ?

Be very specific of what happens, what error messages are displayed, how does Excel react ?
When I select the range of folder names, click Tools|Macro|Macros and Run Create Folders, I get a Stop Message (Compile error: Syntax error. My only option is to click OK and stop the debugging. The path and cell lines are red in the vba module - so I assumed that's where the trouble lies. See the pic, please. Thanks
 

Attachments

  • Capture.JPG
    Capture.JPG
    47 KB · Views: 5
Upvote 0
When I select the range of folder names, click Tools|Macro|Macros and Run Create Folders, I get a Stop Message (Compile error: Syntax error. My only option is to click OK and stop the debugging. The path and cell lines are red in the vba module - so I assumed that's where the trouble lies. See the pic, please. Thanks
Did you see my reply?
I noted a few issues and posted revised code.
 
Upvote 0
I replaced all the quotes and that fixed it......................almost.
It uncovered further issues. The selection box for the path will not alllow for selection, it must be typed in. That's not good.
Back to the drawing board!

Thank you all for getting me past the quote marks. Copy and Paste is not always the best plan.
 
Upvote 0
It uncovered further issues. The selection box for the path will not alllow for selection, it must be typed in. That's not good.
That is correct. Input Box expect text entries to be typed in.
What I sometimes do when I want the user to select a range for the macro, I have then select it BEFORE running the Macro.
Then, at the very top of my Macro, I will have a section like this:
VBA Code:
    Dim ans
    ans = MsgBox("If not, please select No, select the range you want and try running again.", vbYesNo, "Have you selected the range you wanted?")
    If ans = vbNo Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,913
Members
448,532
Latest member
9Kimo3

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