• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

InDesign CS5 VBScript to remove documenst form books

Explorer ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

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.

TOPICS
How to , Scripting

Views

307

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Aug 03, 2022 Aug 03, 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

 

Votes

Translate

Translate
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

The following code also deletes the files:

Set myInDesign = CreateObject("InDesign.Application.2022")
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myBook = myInDesign.ActiveBook
Set myBookContents = myBook.BookContents
For Each myDoc In myBookContents
        Set myFile = myFileSystemObject.GetFile(myDoc.FullName)
        myDoc.Delete
        myFile.Delete
Next

It's been ages since I coded in Visual Basic last time: forgot almost everything.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

Many thanks for our posting.

 

That certainly helps to clarify matters.

 

Do you happen to know of an authoritative reference manual for VB in InDesign, by any chance?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

For reference, you can use Object Browser (e.g. in an MS Office app):

KasyanServetsky_0-1659700269568.png

To get started coding in VBS, I recommend you to read the InDesign scripting tutorial. For me it was enough, then I just googled for VB-specific answers as the questions arose. The InDesign scripting DOM is the same for all languages. You can easily find examples in JS and translate them to VBS which is much less popular nowadays.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

LATEST

One more thing: if you're serious about scripting in VBS, check out the VBScript Editor. I evaluated and liked it. (My personal opinion) It's intuitive and user-friendly so I could write scripts without even reading its documentation. If I had some paid projects to write in VBS, I would definitely buy it.

2022-08-05_15-17-28.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines