Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to remove a certain Table (xlsx-File) from some MXD-Files using python, but I can't finguring out how.

I tried the code sniplet for removing:

import arcpy, os
from arcpy import env

arcpy.env.workspace = 'V:/Projects/ZEL'

mxd =arcpy.mapping.MapDocument('V:/Projects/ZEL/test04.mxd')

df=arcpy.mapping.ListDataFrames(mxd, 'u')[0]

for lyr in arcpy.mapping.ListLayers(mxd, '', df):
        if lyr.dataSource == 'V:\Projects\ZEL\SHP\Daten_111004\ZEL_LB_Tabelle_V3_2010_2030.xlsx':
            arcpy.mapping.RemoveLayer(df, lyr)


print 'fertig'

del mxd

It works, but when I open the new created 'pt.mxd' there is still the symbol of the xlsx-Table with an '!' and you have the option to fix the datasource, because I have removed the path, but not the table...

I hope its not too confusing :)

My question is: Is there a way to remove a xlsx-Sheet from MXD-File without opening?

share|improve this question

You have used forward the forward slash in all your path references except this one 'V:\Projects\ZEL\SHP\Daten_111004\ZEL_LB_Tabelle_V3_2010_2030.xlsx' try fixing that line and see if it works.

share|improve this answer
Or just stick an r in front of the opening quote so it's considered a raw string. – blah238 Oct 23 '11 at 19:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.