Code Not Compatible with XL2003

Tricky

Board Regular
Joined
Jun 8, 2002
Messages
75
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: 4

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,978
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 ?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,744
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,794
Office Version
  1. 365
Platform
  1. Windows
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
 

Tricky

Board Regular
Joined
Jun 8, 2002
Messages
75

ADVERTISEMENT

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: 2

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,744
Office Version
  1. 365
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,794
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Did you see my reply?
I noted a few issues and posted revised code.
I didn't, which is why I posted the same thing :oops:
 

Tricky

Board Regular
Joined
Jun 8, 2002
Messages
75
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,744
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,128,122
Messages
5,628,822
Members
416,342
Latest member
BlueDevil12

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
Top