I tried to execute a .vbs script to run macro inside Excel without opening the workbook. but when I open the workbook I found that nothing changed.
macro for changing column type from text to number percentage.
Public Sub updateColumnFormat()
'Disable screen update and calculation to improve the performance of import
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.EnableCancelKey = True
Application.Calculation = False
Application.ScreenUpdating = False
Sheets("Status").Select
[B:B].Select 'Update data type from text to number of CreditLimit (Column B)
With Selection
.NumberFormat = "General"
.Value = .Value
End With
Selection.Style = "Percent"
Call Refreashstage
'Sheets("Status").Select
'Range("B3").Select
'Sheets("Sales").Select
On Error Resume Next
End Sub
Sub Refreashstage()
Sheets("Status").Select
Range("B3").Select
Sheets("FY21 Sales Forecast").Select
End Sub
.vbs script to execute macro without open the Excel
Set ObjExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\NB\Desktop\test6.xlsm'!Module1.updateColumnFormat"
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
objExcel.Application.Run
you're opening the workbook in the hidden excel application that you created. When you doobjExcel.Application.Quit
, you're closing the workbook after opening it. – ToddlesonobjExcel.Application.Quit
right? but when I open the workbook for check I found that the result doesn't change and the file modified date also doesn't change. So what should I do to call macro to take effect? – alice