To find excel and open it and find a workbook and run a macro from VBS

    main
Sub main() Dim objExcel ''As Object Dim FOUND, FP Dim objShell Dim strPath Set objShell = CreateObject("Wscript.Shell") FP = objShell.SpecialFolders.Item("MyDocuments") & "\TimeLogs\" ''get MyDocuments folder & TimeLogs ''msgbox fp ''Debug FP Set objExcel = GetObject("S:\Users\ron.Allen\Documents\TimeLogs\CURRENT.xlsm").Application If Err Then MsgBox "Excel not open- opening" Set objExcel = CreateObject("Excel.Application") 'Create excel object Else For Each objWorkbook In objExcel.Workbooks If LCase(objWorkbook.Name) = LCase("CURRENT.XLSM") Then ''MsgBox objWorkbook.Name ''objExcel.Application.WindowState = -4143 objWorkbook.Activate 'Activate it FOUND = True Exit For End If Next ''objWorkbook End If '''''''''''''''''''''''''''''''''Open the file if excel was open but file not found. If Not FOUND Then ''msgbox "Workbook Not Found on application, opening." objExcel.Workbooks.Open FP & "CURRENT.xlsm" End If objExcel.Visible = True objExcel.Application.WindowState = -4143 objExcel.Application.Run "Current.xlsm!LogDateTime" End Sub

Comments

Popular posts from this blog

Revit area plans adding new types and references (Gross and rentable)

Powerpoint countdown and current time in slides VBA

Revit 2019 and up tab colorizer