matt_65
04-17-2008, 12:45 AM
Hello,
I have created VBA code that when ran will go through a document find any embedded documents, open them, print them, close the document.
The code functions well, however if the document had an embedded document and it was deleted with markup enabled Word throws an error when I run my script.
The error is the usual error popup window with the red cross, but it doesnt have any text, just an OK button.
My code is as follows:
Public Sub PRINT_Attachments()
'
' PRINT_Attachments Macro -- to print attachments in a doc
' Comments: TYPE=1 is an embedded object
Dim x As Integer
Dim countx As Integer
Dim counte As Integer
For x = 1 To ActiveDocument.InlineShapes.Count
If ActiveDocument.InlineShapes(x).Type = 1 Then
If ActiveDocument.InlineShapes(x).OLEFormat.ProgID <> "Package" Then
ActiveDocument.InlineShapes(x).Activate
With ActiveWindow.View
.ShowRevisionsAndComments = False
.RevisionsView = wdRevisionsViewFinal
End With
ActiveDocument.PrintOut
ActiveDocument.Close
countx = countx + 1
End If
End If
Next
MsgBox "This Document contains: " & countx & " embedded documents"
End Sub
To replicate the issue I am experiencing:
Create a document and insert a few embedded documents (Insert > Object, tick the Icon box and click OK, put some text in the documents and close).
Enable document mark-up
Delete one of the documents
Run scriptI have attached a document which is what I have been using for testing, it contains two embedded documents one has been deleted with mark-up enabled, if you show markup you should see the second document that has been deleted.
The above process results in the error message I am experiencing everytime.
I would like to know if there is a way to skip any documents that have been deleted, or to add some kind of error support. As you can see from my code above, I have turned off document mark-up (so that it shows only the final version), but it still occurs.
Any assistance will be greatly appreciated.
Thanks,
Matt
I have created VBA code that when ran will go through a document find any embedded documents, open them, print them, close the document.
The code functions well, however if the document had an embedded document and it was deleted with markup enabled Word throws an error when I run my script.
The error is the usual error popup window with the red cross, but it doesnt have any text, just an OK button.
My code is as follows:
Public Sub PRINT_Attachments()
'
' PRINT_Attachments Macro -- to print attachments in a doc
' Comments: TYPE=1 is an embedded object
Dim x As Integer
Dim countx As Integer
Dim counte As Integer
For x = 1 To ActiveDocument.InlineShapes.Count
If ActiveDocument.InlineShapes(x).Type = 1 Then
If ActiveDocument.InlineShapes(x).OLEFormat.ProgID <> "Package" Then
ActiveDocument.InlineShapes(x).Activate
With ActiveWindow.View
.ShowRevisionsAndComments = False
.RevisionsView = wdRevisionsViewFinal
End With
ActiveDocument.PrintOut
ActiveDocument.Close
countx = countx + 1
End If
End If
Next
MsgBox "This Document contains: " & countx & " embedded documents"
End Sub
To replicate the issue I am experiencing:
Create a document and insert a few embedded documents (Insert > Object, tick the Icon box and click OK, put some text in the documents and close).
Enable document mark-up
Delete one of the documents
Run scriptI have attached a document which is what I have been using for testing, it contains two embedded documents one has been deleted with mark-up enabled, if you show markup you should see the second document that has been deleted.
The above process results in the error message I am experiencing everytime.
I would like to know if there is a way to skip any documents that have been deleted, or to add some kind of error support. As you can see from my code above, I have turned off document mark-up (so that it shows only the final version), but it still occurs.
Any assistance will be greatly appreciated.
Thanks,
Matt