Run Excel Subprocedure Module from Outlook Module VBA

The below code will run an Excel sub from an Outlook sub. By connecting multiple applications in Microsoft Office, you can make more complex programs that automate more tasks in the Microsoft ecosystem. Just paste this code in your Outlook module in order to run the Excel Module 1 subprocedure Code1 in the workbook Book1.xlsm.

Sub OpenExcel()


Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet


Set appExcel = CreateObject("Excel.Application")

'sets the path for the Workbook that you want to Open from your Outlook Module
strSheet = "C:\Users\Nonaluuluu\Desktop\VBATutorialCode" & _
"Lessons\Outlook and Excel\Book1.xlsm"
appExcel.Workbooks.Open (strSheet)

Set wkb = appExcel.ActiveWorkbook
Set wks = wkb.Sheets(1)


wks.Activate
appExcel.Application.Visible = True

Range("A1").Value = 1

'Runs the subprocedure Code 1 in Module 1 in the Excel workbook Book1.xlsm
 wkb.Application.Run "Module1.Code1"



End Sub

Comments are closed.