0

I have the following script "MyTest.vbs" :

Dim objXLApp
Set objXLApp = CreateObject("Excel.Application")
objXLApp.visible= True
objXLApp.DisplayAlerts = false

objXLApp.Workbooks.Open "F:MyFolder\test.xlsm"
objXLApp.Run "test.xlsm!Module1.main"

objXLApp.Workbooks("test.xlsm").Save
objXLApp.Workbooks("test.xlsm").Close

When I run the script, the following error appear :

Be careful! Parts of your document may include personal information that cannot be removed by the document inspector.

I know that I can fix this error manually, but I would like disable this error with code.

Someone knows how ?

Hippolyte BRINGER
  • 792
  • 1
  • 8
  • 30
  • Does this answer your question? [be careful parts of your document may include personal information that cannot be removed by the Document Inspector](https://stackoverflow.com/questions/21255584/be-careful-parts-of-your-document-may-include-personal-information-that-cannot-b). The other approach is what you already have, `objXLApp.DisplayAlerts = False` – Étienne Laneville Oct 31 '19 at 15:24
  • Thanks but in your link, he solve it "manually". I want the same things with a code. `objxXLApp.DisplayAlerts = False` doesn't work.... – Hippolyte BRINGER Oct 31 '19 at 15:44

1 Answers1

1

There's a VBA (not vbs) method called Workbook.RemoveDocumentinformation(xlRDIAll). Take a look at this https://learn.microsoft.com/office/vba/api/excel.workbook.removedocumentinformation

You should just add this to your Module1.main.

kamikater
  • 101
  • 1
  • 8
  • Thanks, I'm going to look that – Hippolyte BRINGER Oct 31 '19 at 15:47
  • It looks like there's a VBA module in the workbook already where this code could go: `objXLApp.Run "test.xlsm!Module1.main"`. In VBS you could also do `Set objWorkbook = objXLApp.Workbooks.Open("F:MyFolder\test.xlsm")` and then, hopefully, `objWorkbook.RemoveDocumentinformation(99)` – Étienne Laneville Oct 31 '19 at 15:48
  • 1
    Just found that you should first look `If wbk.RemovePersonalInformation = True` – kamikater Oct 31 '19 at 16:03
  • `objworkbook.RemoveDocumentinformation(99)` run, but I have always the pop-up `Be careful! Parts of your document may include personal information that cannot be removed by the document inspector.` Why I have to test if it's equals to `True ` ? – Hippolyte BRINGER Oct 31 '19 at 16:17
  • I guess you might run into an error if your method fails because according to this property there might be cases where you cannot remove the information: https://learn.microsoft.com/office/vba/api/excel.workbook.removepersonalinformation – kamikater Oct 31 '19 at 16:43