Little Help With VBA Code Error.

Badassack

New Member
Joined
Feb 26, 2014
Messages
36
Sub recipecreator()
Dim modName As String
Dim modFolder As String
Dim modnameFolder As String
Dim modrecipeFolder As String
Dim modblockFolder As String
Dim itemName As String
Dim inputOne As String
Dim inputTwo As String
Dim inputThree As String
Dim inputoneCount As Integer
Dim inputtwoCount As Integer
Dim inputthreeCount As Integer
Dim outputCount As Integer
Dim rowCount As Integer
Dim I As Integer



modName = Sheets("Setup").Range("B2").Value
modFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator & Sheets("Setup").Range("B1").Value
modnameFolder = modFolder & "\" & modName
modrecipeFolder = modnameFolder & "\recipes"
modblockFolder = modrecipeFolder & "\blocks"

CreateFolder modFolder
CreateFolder modnameFolder
CreateFolder modrecipeFolder
CreateFolder modblockFolder

rowCount = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row

For I = 2 To rowCount

itemName = Sheets("Data").Cells(I, 1).Value
inputOne = Sheets("Data").Cells(I, 2).Value
inputoneCount = Sheets("Data").Cells(I, 3).Value
inputTwo = Sheets("Data").Cells(I, 4).Value
inputtwoCount = Sheets("Data").Cells(I, 5).Value
inputThree = Sheets("Data").Cells(I, 6).Value
inputthreeCount = Sheets("Data").Cells(I, 7).Value
outputCount = Sheets("Data").Cells(I, 8).Value

If Not inputTwo = vbNullString Then
If Not inputThree = vbNullString Then
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount, inputTwo, inputtwoCount, inputThree, inputthreeCount
Else
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount, inputTwo, inputtwoCount
End If
Else
CreateTextFile modblockFolder, modName, itemName, inputOne, inputoneCount, outputCount
End If
Next I


End Sub
Function CreateFolder(name As String)
If Len(Dir(name, vbDirectory)) = 0 Then
MkDir name
End If
End Function
Function CreateTextFile(modblockFolder As String, modName As String, itemName As String, inputOne As String, inputoneCount As Integer, outputCount As Integer _
, Optional inputTwo As String, Optional inputtwoCount As Integer, Optional inputThree As String, Optional inputthreeCount As Integer)
Dim fso As New FileSystemObject
Dim ts As TextStream

Set ts = fso.CreateTextFile(modblockFolder & "\" & modName & "_" & itemName & ".recipe", True)
ts.WriteLine ("{")
ts.WriteLine (" ""input"" : [")
ts.WriteLine (" { ""item"" : """ & inputOne & """, ""count"" : " & inputoneCount & " }")
If Not inputTwo = vbNullString Then
ts.WriteLine (" { ""item"" : """ & inputTwo & """, ""count"" : " & inputtwoCount & " }")
End If
If Not inputThree = vbNullString Then
ts.WriteLine (" { ""item"" : """ & inputThree & """, ""count"" : " & inputthreeCount & " }")
End If
ts.WriteLine (" ],")
ts.WriteLine (" ""output"" : { ""item"" : """ & itemName & """, ""count"" : " & outputCount & " },")
ts.WriteLine (" ""groups"" : [ ""craftingtable"", ""materials"", ""all"" ]")
ts.WriteLine ("}")
End Function


Getting an "subscript out of range" on this line here,
modName = Sheets("Setup").Range("B2").Value

What is wrong with it? Thank you for any input, while your at it if you can is there anything else that is wrong?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
"subscript out of range" usually means it can't find a sheet with that name !!
Make sure Sheets("Setup") is exactly as typed, no leading / trailling spaces, syntax correct, spelling correct.
 
Upvote 0
Your a genius!! fixed, too bad I got another question, "User-defined type not defined" on this line, "Dim fso As New FileSystemObject" I forgot about this one sorry. thank you.
 
Upvote 0
Have a look at

While in the VBE go to Tools>References and check Microsoft Scripting Runtime
 
Upvote 0
Least somebody loves me !!!...:lol:
glad it worked...:beerchug:
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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