Advertisement
Momogari

A&M Season Export Button Code

Jan 6th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Imports System
  2. 'Imports System.IO
  3.  
  4. Sub ExportToBBCode_NewAnime()
  5.     Dim output As String
  6.     Dim fileName As String
  7.     fileName = ActiveWorkbook.Path & "\output_new.txt"
  8.     Dim i As Integer
  9.     Dim votes As Integer
  10.     i = 0
  11.    
  12.     Dim inputFile As FileSystemObject
  13.     Set inputFile = New FileSystemObject
  14.     Dim fin As TextStream
  15.    
  16.     Set fin = inputFile.OpenTextFile(ActiveWorkbook.Path & "\header.txt", ForReading)
  17.     Dim header As String
  18.     header = fin.Read(10240) '10 kb
  19.    fin.Close
  20.    
  21.     Set fin = inputFile.OpenTextFile(ActiveWorkbook.Path & "\footer.txt", ForReading)
  22.     Dim footer As String
  23.     footer = fin.Read(10240) '10 kb
  24.    fin.Close
  25.    
  26.    
  27.     ' Format output bbcode table
  28.    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]"
  29.     Do
  30.         output = output & "[tr][td][url=" & Application.ActiveSheet.Range("A2").Offset(i, 0).Value & "]"
  31.         output = output & Application.ActiveSheet.Range("B2").Offset(i, 0).Value & "[/url][/td]"
  32.        
  33.         output = output & "[td]" & Application.ActiveSheet.Range("C2").Offset(i, 0).Value & "[/td]"
  34.         output = output & "[td]" & Application.ActiveSheet.Range("D2").Offset(i, 0).Value & "[/td]"
  35.         output = output & "[td]" & Application.ActiveSheet.Range("E2").Offset(i, 0).Value & "[/td]"
  36.         output = output & "[td]" & Application.ActiveSheet.Range("F2").Offset(i, 0).Value & "[/td]"
  37.         output = output & "[td]" & Application.ActiveSheet.Range("G2").Offset(i, 0).Value & "[/td]"
  38.         output = output & "[td]"
  39.         votes = Application.ActiveSheet.Range("H2").Offset(i, 0).Value
  40.         If votes = 0 Then
  41.             output = output & "-"
  42.         Else
  43.             For j = 1 To votes
  44.                 output = output & ":omnom: "
  45.             Next j
  46.         End If
  47.         output = output & "[/td][/tr]"
  48.         i = i + 1
  49.     Loop While Application.ActiveSheet.Range("A2").Offset(i, 0).Value <> ""
  50.     output = output & "[/table]"
  51.    
  52.     ' Now dump to file
  53.  
  54.    Dim fso As FileSystemObject
  55.    Set fso = New FileSystemObject
  56.    Dim fout As TextStream
  57.    Set fout = fso.OpenTextFile(fileName, ForWriting, True)
  58.    fout.Write (header)
  59.    fout.Write (output)
  60.    fout.Write (footer)
  61.    fout.Close
  62.    MsgBox ("BBCode has been written to <output_new.txt>")
  63.  
  64. End Sub
  65.  
  66.  
  67.  
  68. 'Removes non-ascii characters
  69.  
  70. Sub RegExReplace()
  71.  
  72.     Dim RegEx As Object
  73.     Set RegEx = CreateObject("VBScript.RegExp")
  74.     RegEx.Global = True
  75.  
  76.     'RegEx.Pattern = "[^A-Za-z0-9_- :;]"
  77.    RegEx.Pattern = "[^\x00-\x7F]"
  78.     For Each objCell In ActiveSheet.UsedRange.Cells
  79.         objCell.Value = RegEx.Replace(objCell.Value, "")
  80.     Next
  81.  
  82. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement