Clipboard Spam Link Wonks
In Excel columns I have the URLs, and I copy them
Then I look at what is in the clipboard with the aim of adding enough BB Code URL tags
This is what two links look like
Code:
"https" & ":" & "/" & "/" & "www" & "." & "youtube" & "." & "com" & "/" & "watch" & "?" & "v" & "=" & "pGcerfVqYyU" & "&" & "lc" & "=" & "UgwYnetS3HRljX9vOLx4AaABAg" & "." & "94UVSldHOOy9VDJUb" & "_" & "mRBH" & vbCr & vbLf & "https" & ":" & "/" & "/" & "www" & "." & "youtube" & "." & "com" & "/" & "watch" & "?" & "v" & "=" & "pGcerfVqYyU" & "&" & "lc" & "=" & "UgzCtsi4abaxZnZJjZR4AaABAg" & vbCr & vbLf
Fortunately, no surprises, so we just need to add the BB Code URL tags in some convenient way. First thought is to replace the vbCr & vbLf with [/url] & vbCr & vbLf and replace the http with [url] & http
The we put the modified string back in the clipboard
Code:
Option Explicit
'https://excelfox.com/forum/showthread.php/2559-Notes-tests-text-files-manipulation-of-text-files-in-Excel-and-with-Excel-VBA/page5
'https://excelfox.com/forum/showthread.php/2559-Notes-tests-text-files-manipulation-of-text-files-in-Excel-and-with-Excel-VBA?p=16480&viewfull=1#post16480
'https://excelfox.com/forum/showthread.php/2559-Notes-tests-text-files-manipulation-of-text-files-in-Excel-and-with-Excel-VBA/page5#post16480
Sub CopyExcelColumnSpamURL()
Selection.Copy ' This will put it in the clipboard
'Dim objCliCodeCopied As DataObject '**Early Binding. This is for an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. So I name it CLIpboardSend. But it is a DataObject. It has the Methods I need to send text to the Clipboard
' Set objCliCodeCopied = New DataObject '**Must enable Forms Library: In VB Editor do this: Tools -- References - scroll down to Microsoft Forms 2.0 Object Library -- put checkmark in. Note if you cannot find it try OR IF NOT THERE..you can add that manually: VBA Editor -- Tools -- References -- Browse -- and find FM20.DLL file under C:\WINDOWS\system32 and select it --> Open --> OK. https://web.archive.org/web/20140610055224/http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
' ( or instead of those two lines Dim obj As New DataObject ). or next two lines are.....Late Binding equivalent'
Dim objCli As Object ' Late Binding equivalent' If you declare a variable as Object, you are late binding it. https://web.archive.org/web/20141119223828/http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/
Set objCli = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") ' https://web.archive.org/web/20140610055224/http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
objCli.GetFromClipboard 'All that is in the Clipboard goes in this Data Object initial instance of the Class
Dim SpamURLs As String ' String varable to take the moodified code. This can be very long, like my cock
Let SpamURLs = objCli.GetText() 'retrieve the text in the initial instance of the Class. ( In this case the original code modifies to have code lines )
' Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(SpamURLs)
Let SpamURLs = Replace(SpamURLs, vbCr & vbLf, "[/uRl]" & vbCr & vbLf, 1, -1, vbBinaryCompare)
Let SpamURLs = Replace(SpamURLs, "http", "[uRl]http", 1, -1, vbBinaryCompare)
' Make a data Object to put back in clipboard. This a Another Object from class just to demo, could have used the first
'Dim objDatCliBackIn As DataObject
' Set objDatCliBackIn = New DataObject 'Set to a new Instance ( Blue Print ) of dataobject
Dim objDatCliBackIn As Object
Set objDatCliBackIn = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
objDatCliBackIn.SetText "Alan Spam Tests" & vbCr & vbLf & SpamURLs 'Make Data object's text equal to the long string of the modified code
objDatCliBackIn.PutInClipboard 'Place current Data object into the Clipboard, effectivelly putting its text, which is oue final code in the Clipcoard
End Sub
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwhVTFaD469mW9wO194AaABAg. 9gJzxwFcnPU9gORqKw5tW_
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugyb8nmKKoXvcdM58gV4AaABAg
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwvvXcl1oa79xS7BAV4AaABAg
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgxvIFArksPprylHXYZ4AaABAg
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxUbeYSvsBH2Gianox4AaABAg. 9VYH-07VTyW9gJV5fDAZNe
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgyhQ73u0C3V4bEPhYB4AaABAg
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg. 9fsvd9zwZii9gMUka-NbIZ
https://www.youtube.com/watch?v=jdPeMPT98QU
https://www.youtube.com/watch?v=QdwDnUz96W0&lc=Ugx3syV3Bw6bxddVyBx4AaABAg
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
ps1 PowerShell script text like files
Insert some lines without losing what’s there / Retain Comments / Shift what’s there to the right
A fairly simple problem
A common requirement for me is that I want to put some raw code lines into an existing script or VBA code, but I don’t want to change the line numbers referring to where they do in the existing code file.
This might occur if I want to replace some coding, but would like to keep the existing coding for future reference, possibly commented out to the right
What I might do typically for just a few lines is to manually put a comment at the start left of lines to be replaced, and then shift those now comments a few spaces to the right, then start typing the replacement lines from the left, which then pushed those comments to the left
Pictorially this is what I mean for the simple case of wanting to replace just one line
Code:
Sub Original()
Dim Msg As String
Let Msg = "Hello"
MsgBox Prompt:="Hello shit World"
End Sub
Sub ModifiedByInsertingNewCodeLine()
Dim Msg As String
Let Msg = "Hello"
Debug.Print "Hello shit World" ' MsgBox Prompt:="Hello shit World"
End Sub
That’s easy for a few lines, but for a lot of lines it’s a tedious pain in the arse
.ps1 PowerShell text like code lines
Currently have some large .ps1 PowerShell files that I am inserting a lot of lines in and want to do it in the way I am talking about
In this post I will check out the format of the files first, in case there are any unusual “invisible” characters in them, since I have seen that in some PowerShell related text files ( https://excelfox.com/forum/showthrea...ll=1#post15357 https://excelfox.com/forum/showthrea...age3#post15357 )
Here is a File of 250 code line, that I want to put in,
Share ‘blockIPhostsRawAll250.ps1’ https://app.box.com/s/7019x59uvvxt7osvb0tojr0z4g7bfdgk ,
and here is just the first 4 lines for testing here,
Share ‘blockIPhosts4Lines.ps1’ https://app.box.com/s/37pjl9jfk9wue413xewgcjg1cdwk9dwb .
Here is a File I want to put that in from about line 200,
Share ‘Temp7BeforeIPhostsInsert.ps1’ https://app.box.com/s/fttlmwny6y4s5ub1q66kvqbrw2ppxdwz
, and here is just the first 4 lines of that for testing here,
Share ‘Temp7BeforeIPhostsInsertFirst4Lines.ps1’ https://app.box.com/s/bimxv550fpkoqndt8rz421s9vmcsorif .
Simple macro …_
Code:
'Here is a File of 250 code line, that I want to put in,
'Share ‘blockIPhostsRawAll250.ps1’ https://app.box.com/s/7019x59uvvxt7osvb0tojr0z4g7bfdgk ,
'and here is just the first 4 lines for testing here,
'Share ‘blockIPhosts4Lines.ps1’ https://app.box.com/s/37pjl9jfk9wue413xewgcjg1cdwk9dwb .
'Here is a File I want to put that in from about line 200,
'Share ‘Temp7BeforeIPhostsInsert.ps1’ https://app.box.com/s/fttlmwny6y4s5ub1q66kvqbrw2ppxdwz
', and here is just the first 4 lines of that for testing here,
'Share ‘Temp7BeforeIPhostsInsertFirst4Lines.ps1’ https://app.box.com/s/bimxv550fpkoqndt8rz421s9vmcsorif .
'
'
Sub LookInFirstBitOfTemp4andIPhosts() ' https://excelfox.com/forum/showthread.php/2559-Notes-tests-text-files-manipulation-of-text-files-in-Excel-and-with-Excel-VBA?p=16366&viewfull=1#post16366
' Get the text file as a long single string
Dim FileNum As Long: Let FileNum = FreeFile(1) ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
Dim PathAndFileName As String, TotalFile As String
Let PathAndFileName = ThisWorkbook.Path & Application.PathSeparator & "test4lines.txt" ' CHANGE TO SUIT From vixer zyxw1234 : http://www.eileenslounge.com/viewtopic.php?f=30&t=34629 DF.txt https://app.box.com/s/gw941dh9v8sqhvzin3lo9rfc67fjsbic
Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundamental type data input...
Let TotalFile = Space(LOF(FileNum)) '....and wot receives it has to be a string of exactly the right length
Get #FileNum, , TotalFile 'Debug.Print TotalFile
'Let TotalFile = Replace(TotalFile, Chr(0), "", 1, -1, vbBinaryCompare) ' https://i.postimg.cc/t43HCQr9/Rather-a-lot-of-Chr-0-s.jpg
'Let TotalFile = Replace(TotalFile, Chr(255) & Chr(254) & vbCr & vbLf, "", 1, 1, vbBinaryCompare)
Close #FileNum
Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(TotalFile)
End Sub
Here is a view in the text editor of those first 4 lines, followed by what my WtchaGot_Unic_NotMuchIfYaChoppedItOff( function gives me
https://i.postimg.cc/n9kqsv63/First4...2ps1-Files.jpg
Code:
Function BlochIPhosts {param([int]$Testie)
$Check = $Testie
Write-Host "Adding telemetry domains to hosts file" # Write-Output "Adding telemetry domains to hosts file"
$hosts_file = "$env:systemroot\System32\drivers\etc\hosts"
"Function BlochIPhosts " & Chr(123) & "param" & "(" & Chr(91) & "int" & Chr(93) & "$" & "Testie" & ")" & vbCr & vbLf & " " & "$" & "Check " & "=" & " " & "$" & "Testie" & vbCr & vbLf & "Write" & "-" & "Host " & """" & "Adding telemetry domains to hosts file" & """" & " " & "#" & " Write" & "-" & "Output " & """" & "Adding telemetry domains to hosts file" & """" & vbCr & vbLf & "$" & "hosts" & "_" & "file " & "=" & " " & """" & "$" & "env" & ":" & "systemroot" & "\" & "System32" & "\" & "drivers" & "\" & "etc" & "\" & "hosts" & """"
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles() #
Remove-Variable * -ErrorAction SilentlyContinue # is needed or else a removed variable is still there when fucking about with variables. by default variables are persistant.
$ErrorActionPreference = 'SilentlyContinue'
"Add" & "-" & "Type " & "-" & "AssemblyName System" & "." & "Windows" & "." & "Forms" & vbLf & Chr(91) & "System" & "." & "Windows" & "." & "Forms" & "." & "Application" & Chr(93) & ":" & ":" & "EnableVisualStyles" & "(" & ")" & " " & "#" & vbLf & "Remove" & "-" & "Variable " & Chr(42) & " " & "-" & "ErrorAction SilentlyContinue " & "#" & " is needed or else a removed variable is still there when fucking about with variables" & "." & " by default variables are persistant" & "." & vbLf & "$" & "ErrorActionPreference " & "=" & " " & "'" & "SilentlyContinue" & "'"
Here is a screenshot of the two files in Notepad text editor
https://i.postimg.cc/n9kqsv63/First4...2ps1-Files.jpg
So, no major problems or surprises, ( or so I thought – see next post )
It looks like a different line separator is used sometimes. But we have seen this before.
I have a slight personal tendency to prefer the two character line separator, vbCr & vbLf , and also the first file was the main one in which the other will be inserted, so I will do a simple conversion to the file to be inserted to replace all vbLf with vbCr & vbLf
One small interesting note. I don’t have a last trailing line feed character or characters. That is not so usual, at least I have not experienced it yet so far in playing around with .csv and other text files