I'm making a program that does many different tasks and using it as an opportunity to get more familiar with VBA. Right now, this code is in a separate file until I get the foundation of the code solid then I'll migrate the changes to the actual file it is meant for.
To sum up what I am trying to do:
Take a folder with files in it that use this naming structure: "SOP-JV-001-CHL-Letter Lock for Channel Letters-EN"
Split up that filename using the "-" as the delimiter
Sub GenerateFileLinks()
ActiveSheet.Cells.Clear
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("C:\Users\jbishop\Desktop\SOPs With New Names")
i = 0
'Loop through each file in the directory
For Each objFile In objFolder.Files
'SOP ID Range
Set rngSOPID = Range(Cells(i + 1, 1), Cells(i + 1, 1))
'DeptCode Range
Set rngDeptCode = Range(Cells(i + 1, 2), Cells(i + 1, 2))
'URL Range
Set rngURL = Range(Cells(i + 1, 3), Cells(i + 1, 3))
'Lang Range
Set rngLang = Range(Cells(i + 1, 4), Cells(i + 1, 4))
Set Filename = Split(objFile.Name, "-")
'Create hyperlink in each cell
ActiveSheet.Hyperlinks.Add Anchor:=rngURL, Address:=objFile.Path, TextToDisplay:=Filename(4)
i = i + 1
Next objFile
End Sub
Okay, getting an error: Type Mismatch...I've used a split statement like that before. It's so close!