Reputation: 577
I wrote a macro in Outlook to set the value of a cell in Excel file which is opening.
Sub test()
Dim objExcel As Object, WB As Object, WS As Object
Set objExcel = GetObject(, "Excel.Application")
objExcel.Visible = True
Set WB = objExcel.Workbooks("Book1.xlsm")
WB.Activate
Set WS = WB.Worksheets("Sheet1")
AppActivate "Microsoft Outlook"
WS.Range("A1").Value = "hoho"
End Sub
It sets the value of the cell, but I still stand in Outlook.
How can I display the Excel file instead of Outlook?
Upvotes: 0
Views: 378
Reputation:
The way to do that is to minimize the Application Window and then maximize it.
objExcel.WindowState = xlMinimized
objExcel.WindowState = xlMaximized
Upvotes: 1