Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Imports System
- 'Imports System.IO
- Sub ExportToBBCode_NewAnime()
- Dim output As String
- Dim fileName As String
- fileName = ActiveWorkbook.Path & "\output_new.txt"
- Dim i As Integer
- Dim votes As Integer
- i = 0
- Dim inputFile As FileSystemObject
- Set inputFile = New FileSystemObject
- Dim fin As TextStream
- Set fin = inputFile.OpenTextFile(ActiveWorkbook.Path & "\header.txt", ForReading)
- Dim header As String
- header = fin.Read(10240) '10 kb
- fin.Close
- Set fin = inputFile.OpenTextFile(ActiveWorkbook.Path & "\footer.txt", ForReading)
- Dim footer As String
- footer = fin.Read(10240) '10 kb
- fin.Close
- ' Format output bbcode table
- output = "[table][tr][td][b]Name[/b][/td][td][b]Studio[/b][/td][td][b]Premieres[/b][/td][td][b]Episodes[/b][/td][td][b]Where to Watch[/b][/td][td][b]Genre[/b][/td][td][b]Votes[/b][/td][/tr]"
- Do
- output = output & "[tr][td][url=" & Application.ActiveSheet.Range("A2").Offset(i, 0).Value & "]"
- output = output & Application.ActiveSheet.Range("B2").Offset(i, 0).Value & "[/url][/td]"
- output = output & "[td]" & Application.ActiveSheet.Range("C2").Offset(i, 0).Value & "[/td]"
- output = output & "[td]" & Application.ActiveSheet.Range("D2").Offset(i, 0).Value & "[/td]"
- output = output & "[td]" & Application.ActiveSheet.Range("E2").Offset(i, 0).Value & "[/td]"
- output = output & "[td]" & Application.ActiveSheet.Range("F2").Offset(i, 0).Value & "[/td]"
- output = output & "[td]" & Application.ActiveSheet.Range("G2").Offset(i, 0).Value & "[/td]"
- output = output & "[td]"
- votes = Application.ActiveSheet.Range("H2").Offset(i, 0).Value
- If votes = 0 Then
- output = output & "-"
- Else
- For j = 1 To votes
- output = output & ":omnom: "
- Next j
- End If
- output = output & "[/td][/tr]"
- i = i + 1
- Loop While Application.ActiveSheet.Range("A2").Offset(i, 0).Value <> ""
- output = output & "[/table]"
- ' Now dump to file
- Dim fso As FileSystemObject
- Set fso = New FileSystemObject
- Dim fout As TextStream
- Set fout = fso.OpenTextFile(fileName, ForWriting, True)
- fout.Write (header)
- fout.Write (output)
- fout.Write (footer)
- fout.Close
- MsgBox ("BBCode has been written to <output_new.txt>")
- End Sub
- 'Removes non-ascii characters
- Sub RegExReplace()
- Dim RegEx As Object
- Set RegEx = CreateObject("VBScript.RegExp")
- RegEx.Global = True
- 'RegEx.Pattern = "[^A-Za-z0-9_- :;]"
- RegEx.Pattern = "[^\x00-\x7F]"
- For Each objCell In ActiveSheet.UsedRange.Cells
- objCell.Value = RegEx.Replace(objCell.Value, "")
- Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement