Thursday, July 6, 2023

Email send Using Powershell

$username = 'donotreply@domain.com'

$password = 'XXXXXXXXX'

$body = Get-Content -Path C:\Users\Location.txt -Raw

[SecureString]$securepassword = $password | ConvertTo-SecureString -AsPlainText -Force 

$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securepassword

Send-MailMessage -SmtpServer 2XX.XXX.xx.xx -Port 587 -From donotreply@domain.com -To email@domain.com -Cc email1@domain.com,email2@domain.com -Subject 'EMAIL SUBJECT' -Body $body  -Credential $credential -Attachments "C:\Users\locationfile.txt"; 




Split the same worksheet by Number of rows in XL

 ALT +F11


Split the same worksheet by Number of rows in XL

Past the sheet VBA code on sheet you wanted to split 


Sub SplitData()


Dim WorkRng As Range


Dim xRow As Range


Dim SplitRow As Integer


Dim xWs As Worksheet


On Error Resume Next


xTitleId = "KutoolsforExcel"


Set WorkRng = Application.Selection


Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)


SplitRow = Application.InputBox("Split Row Num", xTitleId, 5, Type:=1)


Set xWs = WorkRng.Parent


Set xRow = WorkRng.Rows(1)


Application.ScreenUpdating = False


For i = 1 To WorkRng.Rows.Count Step SplitRow


    resizeCount = SplitRow


    If (WorkRng.Rows.Count - xRow.Row + 1) < SplitRow Then resizeCount = WorkRng.Rows.Count - xRow.Row + 1


    xRow.Resize(resizeCount).Copy


    Application.Worksheets.Add after:=Application.Worksheets(Application.Worksheets.Count)


    Application.ActiveSheet.Range("A1").PasteSpecial


    Set xRow = xRow.Offset(SplitRow)


Next


Application.CutCopyMode = False


Application.ScreenUpdating = True


End Sub