I tried this again but i am not getting an error.
The Export_Output layer is a shapefile and the fields that are in the layer that i don't need are
Shape*, OBJECTID, Shape_Leng & Shape_Area
Traceback (most recent call last):
File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\TableToExcel.py", line 224, in <module>
arcpy.GetParameter(3))
File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\TableToExcel.py", line 194, in table_to_excel
for row in cursor:
RuntimeError: Cannot find field ''
Failed to execute (TableToExcel).
import arcpy
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "Export_Output")[0]
#Exports NotifiedLots tabel to excel table
intable = lyr
# Create a fieldinfo object
fieldInfo = arcpy.FieldInfo()
# Get the fields from the input
fields= arcpy.ListFields(intable)
for field in fields:
if field.type != 'OID' and field.type != 'Shape':
fieldInfo.addField(field.name, field.name, "VISIBLE", "")
if field.type == 'OID':
fieldInfo.addField(field.name, field.name, "HIDDEN", "")
# Create table view
arcpy.MakeTableView_management(intable, "Notif_view", "", "", fieldInfo)
# Export to Excel
arcpy.conversion.TableToExcel("Notif_view", r"C:\TEMP\Notif_view.xls")