AI with MS OFFICE
JATAN SHAH
• https://link.jatanshah.in/pptdownload
• https://www.office.com/launch/powerpoint
• https://wepik.com/ai-presentations
Macro with Developer
Create an excel macro that copies data from all files in a folder that the user selects into the sheet named "Compile Data Here"
of the current excel workbook.
A box should open allowing the user to select the folder.
Once folder is selected, all data inside the excel files inside the folder will be copied and stacked one below the other.
Sub CopyDataFromFilesInFolder()
Dim folderPath As String
Dim fileName As String
Dim currentWorkbook As Workbook
Dim targetWorksheet As Worksheet
Dim currentWorksheet As Worksheet
' Open file picker dialog to choose folder
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select a folder containing Excel files"
If .Show = True Then
folderPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
' Get current workbook and target worksheet
Set currentWorkbook = ActiveWorkbook
Set targetWorksheet = currentWorkbook.Sheets("Compile Data Here")
' Loop through all Excel files in the selected folder
fileName = Dir(folderPath & "\*.xlsx")
Create a macro to send emails using outlook to email ids given in column B
Subject will be "Congratulations! You made total sales of X last month."
"X" here will be the values from column A.
Body will be "We are proud to have you as an employee of ITC. Keep up the good work"
Keep the email id given in cell D2 in CC for all emails sent.
Show a message box saying "All emails are sent." once done.
Sub SendCongratulationEmails()
Dim objOutlook As Object
Dim objMail As Object
Dim lastRow As Long
Dim i As Long
'Get the last row of data in column B
lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
'Create a new Outlook object
Set objOutlook = CreateObject("Outlook.Application")
'Loop through all email addresses in column B
For i = 2 To lastRow
'Create a new email message
Set objMail = objOutlook.CreateItem(0)
'Add the recipient email address and subject line
With objMail
.To = Cells(i, 2).Value
.CC = Cells(2, 4).Value
.Subject = "Congratulations! You made total sales of " & Cells(i, 1).Value & " last month."
Write an excel macro to add one empty row after every row
Sub AddEmptyRows()
Dim i As Long, lastRow As Long
lastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For i = lastRow To 1 Step -1
Rows(i + 1).Insert Shift:=xlDown
Next i
End Sub