Skip to content

Instantly share code, notes, and snippets.

@guyhughes
Last active August 29, 2015 14:09
Show Gist options
  • Save guyhughes/1a896b956e29afb8c5ee to your computer and use it in GitHub Desktop.
Save guyhughes/1a896b956e29afb8c5ee to your computer and use it in GitHub Desktop.
'
' Formats tweet from clipboard and inserts it
' Assumptions:
' - Tweet text in clipboard, with user & tweet separated by a line break.
' - No trailing spaces; uses Trim().
'
Sub PasteAndFormatTweet()
Dim c As New DataObject
Dim strClip As String
Dim loc As Integer
Call SelectWholeLine
' get clipboard
c.GetFromClipboard
strClip = c.GetText
'COLON ADDING ROUTING
' find first space
loc = InStr(strClip, Chr(13))
'add colon
strClip = Insert(strClip, ": ", loc)
' REMOVE ROUTINE
strClip = RemoveSpacing(strClip)
' INSERT ROUTINE
Call CursorToEOL
' insert at cursor
Selection.TypeText (strClip)
' TRIM ROUTINE
Call SelectWholeLine
Call TrimSelection
Call CursorToEOL
End Sub
'
' Prompts for number of retweets, inserts
' Assumption: line's first colon is in a standard position
' - i.e. @tweeter: tweetexthere
'
' Result: @tweets [2 retweets]: tweetexthere
'
Sub AddRetweetsCount()
Dim rts As String
Call SelectWholeLine
rts = InputBox("How many RTs?", "0")
' Exit if there
If rts <> "" Then
Dim text As String
text = " [" + rts + " retweets]:"
Else
MsgBox ("Did not receive user input for number of retweets. Exiting")
Exit Sub
End If
With Selection.find
.ClearFormatting
.Replacement.ClearFormatting
.text = ":"
.Replacement.text = text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute replace:=wdReplaceOne
End With
' INSERT
Selection.TypeText (text)
End Sub
Sub CursorToEOL()
Selection.EndKey Unit:=wdLine
End Sub
Sub SelectWholeLine()
Selection.Expand wdLine
End Sub
Function RemoveSpacing(strClip) As String
'remove tabs
RemoveSpacing = replace(strClip, Chr(9), "")
'remove
RemoveSpacing = replace(RemoveSpacing, Chr(11), "")
'remove
RemoveSpacing = replace(RemoveSpacing, Chr(10), "")
'remove
RemoveSpacing = replace(RemoveSpacing, Chr(13), "")
End Function
Sub TrimSelection()
Dim r1 As Range
Dim str1 As String
Set r1 = Selection.Range
str1 = Trim(r1.text)
r1.text = str1
End Sub
Function Insert(source As String, str As String, i As Integer) As String
Insert = Mid(source, 1, i) & str & Mid(source, i + 1, Len(source) - i)
End Function
' DREAMING
' In an ideal world, we'd just click on a tweet, capture its ID
' and send that to a text file.
' Then we'd read the text file, and pull the data about the tweets from the API
' and insert relevant stats automatically into another text file (or HTML5 storage).
' We'd pull the data from the text file, refresh it against the API and print a report.
' We'd also have auto-sort and drag-and-drop for the tweets.
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment