0

This seems like it should be really simple, but for some reason I can't get it to work at all. The following code has no effect whatsoever:

function setExcelImportPrefs() {  
  with(app.excelImportPreferences){
    rangeName = "A1:Z300";
    sheetName = "whatever";
    tableFormatting = TableFormattingOptions.excelFormattedTable;
  }
}

And this doesn't work either:

function setExcelImportPrefs() {  
  with(app.excelImportPreferences){
    app.excelImportPreferences.rangeName = "A1:Z300";
    app.excelImportPreferences.sheetName = "whatever";
    app.excelImportPreferences.tableFormatting = TableFormattingOptions.excelFormattedTable;
  }
}

What am I doing wrong? I've Googled everything, and I'm at my wits end. (Note: I have InDesign CS6, version 8.0)

Edit: Put in a bracket that I accidentally left out when I was copying-and-pasting.

belscb
  • 1
  • 1
  • Just making sure; no offense meant. This *is* part of a larger script, right? You call this function to set the parameters, and then you do a `targetText.place(..)`; and then, when you run the script, what? Nothing happens at all, or you get an error (if so, which one), or *something* happens (what?). Place an `alert` before and after these lines; do they show up? – Jongware Jul 25 '14 at 21:00
  • 1
    Yes, it's part of a larger script. I've placed alerts before, after, and inside this function, and they always alert. So the function is being run, it's just not having the desired effect. – belscb Jul 27 '14 at 15:00
  • The user imports and places the Excel document using a prompt in the script, so they can select the specific Excel document they want to use. I *want* it to import only a specific worksheet later in the document, and to import cells A1:Z300. But instead it only imports the first worksheet by default, and it cuts out row A and column A because they're empty. That messes up the whole process I have in mind. I need some way to specify the worksheet, the range, and also the formatting. Hence, my attempted code above. Hopefully that gives some useful context. – belscb Jul 27 '14 at 15:03

1 Answers1

0

I'm not familiar with these settings, but you seem to have be missing a bracket. Just get rid of the with syntax all together and try

function setExcelImportPrefs() {    
  app.excelImportPreferences.rangeName = "A1:Z300";
  app.excelImportPreferences.sheetName = "whatever";
  app.excelImportPreferences.tableFormatting = TableFormattingOptions.excelFormattedTable;
}
Anna Forrest
  • 1,711
  • 14
  • 21
  • Oops, I forgot to copy-and-paste the last bracket above. It's there in my actual code; I just forgot to put it in my post above. So that wasn't the problem. – belscb Jul 25 '14 at 17:39
  • Thank you for the idea, but this solution doesn't work. Leaving out the with syntax does nothing either. – belscb Jul 25 '14 at 17:41
  • Is it XLSX file? Can you save it as XLS and run for test? – Cashmirek Dec 03 '16 at 20:08