Cannot run the macro main . the macro may not be available in this owkrbook or all macross disabled

I wanted to run and invoke code that converts cells to numbers in excel but I got an error which is on the title above. Anyone has an idea ? thank you.

image

Code
Dim xlsApp As New Excel.Application
xlsApp.Visible = True
Dim xlsWorkbook As Excel.Workbook = xlsApp.Workbooks.Open("\file.xlsx")
Dim constant As Excel.XlCellType
constant = Excel.XlCellType.xlCellTypeConstants
With xlsWorkbook.Worksheets(1).Range(“E6:E22”).SpecialCells(constant, 2)
.NumberFormat = “General”
.Value = .Value
End With

save the file as .vbs extention not in the text

Also, make sure you have the below setting done in excel…

@Pravin_Patil1 still the same error even using .vbs

alerady have enable trust access to the VBA project model in excel also

cannot run the macro ‘Main’ the macro may not be available in this owkrbook or all macross disabled

Hi,
if you invoke VBA code inside Excel Application Scope you have to name your Sub:

If Sub name is “Main()” you invoke path and name “Main”.
image

If Sub name is eg. “ClearFilter()” you invoke path and name “ClearFilter”
image
image

Where is Main Function name in your MAcro code?

It should be like below

Sub Main()

Dim xlsApp As New Excel.Application
xlsApp.Visible = True
Dim xlsWorkbook As Excel.Workbook = xlsApp.Workbooks.Open("\file.xlsx")
Dim constant As Excel.XlCellType
constant = Excel.XlCellType.xlCellTypeConstants
With xlsWorkbook.Worksheets(1).Range(“E6:E22”).SpecialCells(constant, 2)
.NumberFormat = “General”
.Value = .Value
End With
End Sub

Syntax error on With xlsWorkbook.Worksheets(1).Range(“E6:E22”).SpecialCells(constant, 2)

Now macro is running. You need to look on coding portion…

what do you think is the problem when this line 'With xlsWorkbook.Worksheets(1).Range(“E6:E22”).SpecialCells(constant, 2)
’ ?

still an error @Adrian_Star

I put invoke vba code inside excel application scope

Do you have set macro settings in Excel Application Scope options?

image
File with macro can by in file type “.txt” eg. “Data\macro.txt”

@Adrian_Star


indent preformatted text by 4 spaces
Sub Converter()

Dim xlsApp As New Excel.Application
xlsApp.Visible = True
Dim xlsWorkbook As Excel.Workbook = xlsApp.Workbooks.Open("\\File.xlsx")
Dim constant As Excel.XlCellType
constant = Excel.XlCellType.xlCellTypeConstants
With xlsWorkbook.Worksheets(1).Range("E6:E22").SpecialCells(constant, 2)
.NumberFormat = “General”
.Value = .Value
End With
End Sub