Skip to main content

Posts

Showing posts from November 16, 2020

Microsoft VBA Script to save mail merged word documents into separate files

' First add the mail merged fields and save the document 'Then reopen the word document and click no to SQL import and open VBA editor and paste this script 'Finally save this as a macro enabled document and test this code 'Happy coding Option Explicit Dim FOLDER_SAVED As String Dim SOURCE_FILE_PATH As String Function ReplaceIllegalCharacters(strIn As String, strChar As String) As String     Dim strSpecialChars As String     Dim i As Long     strSpecialChars = "~""#%&*:<>?{|}/\[]" & Chr(10) & Chr(13)     For i = 1 To Len(strSpecialChars)         strIn = Replace(strIn, Mid$(strSpecialChars, i, 1), strChar)     Next     ReplaceIllegalCharacters = strIn End Function Sub TestRun() Dim MainDoc As Document, TargetDoc As Document Dim dbPath As String, FileName As String, Folder As String Dim recordNumber As Long, totalRecord As Long, startingRec As Integer, endingIndex As Integer Dim Answer As VbMsgBoxResult Set MainDoc = ActiveDocument FO

Basic Shell script to perform Mathematical functions

 #!/bin/bash : ' BASH Script that mimics a 4 function calculator. A function called addition. This function will take two arguments and will return the sum of these two arguments. Be sure to check that the values are valid numbers. A function called subtraction. This function will take two arguments and will return the difference of these two arguments. A function called multiply. This function will take two arguments and will return the product of these two arguments. A function called divide. This function will take two arguments and will return the quotient of these two arguments. First argument is an option that chooses what to do with the two other arguments. The options should be as follows: -a Perform addition of the two numbers -s Perform subtraction of the two numbers -m Perform multiplication of the two numbers -d Perform division of the two numbers Second argument should be the first number used for the math problem Third argument should be the second number used fo

Microsoft PowerShell Script to Rename and move files to different Directory

  <# This Script will rename the files on a folder path and move them into a single folder #> #Set your source path here $oldPath = "C:\test\old"; #Set your destination path here $newpath = "C:\test\new"; #> This will loop through all the files in the source folder path recursively and and get there full file path and add to the $files variable #> $files = Get-ChildItem -Path $oldPath -File -Recurse -Force; # |  select FullName $ter=0; $olddir="adad"; foreach ($file in $files)  { $ter++; #> this will get only the directory name of the files #> $dirpath = [System.IO.Path]::GetDirectoryName($file.FullName); $dirname = [System.IO.Path]::GetFileName($dirpath); $foo = $dirname.Replace("`n", ""); $foo = $foo.Replace(" ", ""); $foo = $foo.Replace("`t", ""); $olddir=$foo; $oldname = $file.FullName; $oldext= $file.Extension; $newname = $foo+$ter.ToString()+$oldext;