Skip to main content
Known Participant
August 3, 2022
Answered

InDesign CS5 VBScript to remove documenst form books

  • August 3, 2022
  • 2 replies
  • 755 views

Can anyone advise on a suitable InDesign CS5 VBScript to remove documents from books?

 

I have used the Add method succesfully to add documents to books

eg

myBook.bookcontents.add (FilePathandName)

 

and I assume that the Remove method removes them - but I just can't seem to get the syntax right.

 

I would like to be able to remove specific documents or remove all documents.

 

Any suggestions would be welcome.

This topic has been closed for replies.
Correct answer Kasyan Servetsky

Try this to remove all docs:

Set myInDesign = CreateObject("InDesign.Application.2022")
Set myBook = myInDesign.ActiveBook
Set myBookContents = myBook.BookContents
For Each myDoc In myBookContents
        myDoc.Delete
Next

 

2 replies

Kasyan Servetsky
Kasyan ServetskyCorrect answer
Braniac
August 3, 2022

Try this to remove all docs:

Set myInDesign = CreateObject("InDesign.Application.2022")
Set myBook = myInDesign.ActiveBook
Set myBookContents = myBook.BookContents
For Each myDoc In myBookContents
        myDoc.Delete
Next

 

Known Participant
August 4, 2022

Many thanks for your posting.

 

That was excellent.

 

The following code you advised removed all of the documenst from the book

Set myBookContents = myBook.BookContents
For Each myDoc In myBookContents
myDoc.Delete
Next

 

I'm a bit puzzled as to where the Remove method comes in though - as far as I can tell the Delete method in the above example eemoves the documents from the book but doesn't actually delete them from their original location - which is what I would have ecpected for a delete.

 

But I am impressed by your advice.

 

Kasyan Servetsky
Braniac
August 4, 2022

You can't delete files with InDesign DOM only: you have to use FSO (file system object) for this.

Braniac
August 3, 2022

Hi@chrisnaylor ,

this is for ExtendScript, but I think it's also true with the DOM for VBscript:

The book.bookContents collection has the method remove(). There is no argument in this method.

So you have to identify the document you want to remove in a different way. There is property fullName for example.

 

With ExtendScript you can remove all items of the bookContents collection like that:

myBook.bookContents.everyItem().remove();

If you know the position of the document in your book file, e.g. you want to remove the first one ( counting starts with 0 in ExtendScript ) :

myBook.bookContents[0].remove();

 

So specify perhaps how you identify a document you want to remove and I can give you more hints.

 

DOM documentation for ExtendScript with InDesign:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#BookContent.html#d1e61670

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Book.html

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Known Participant
August 3, 2022

Many thanks for your posting.

 

When I try:

myBook.bookContents.everyItem.remove

or

myBook.bookContents.everyItem().remove()

 

It fails with error emssage:

 

Object doesn't support this property or method.

 

I have tried numerous permutations on this theme but just can't seem to get it right!