Delete web scripts pasted from web pages

P

Paul Martin

I regularly paste web pages into Word which I then format. With non-
printable characters displaying on the screen, any web scripts show up
at yellow boxes, and I'd like to delete these. The following code
causes a crash in Word (forced restart of Word) on the line "If Not
ishp.Script Is Nothing Then". Any suggestions appreciated.

Paul Martin
Melbourne, Australia


Dim ishp as InlineShape

For Each ishp In ActiveDocument.InlineShapes
If Not ishp.Script Is Nothing Then
ishp.Delete
End If
Next ishp
 
H

Helmut Weber

Hi Paul,

just delete the error causing line.

Sub Test556()
Dim ishp As InlineShape
For Each ishp In ActiveDocument.InlineShapes
ishp.Delete
Next ishp
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
P

Paul Martin

Hi Helmut

First, ishp.Delete does not delete the script.
Secondly, if I don't differentiate between these and other shapes, the
code will delete images I want to keep.
Any thoughts?

Danke

Paul
 
H

Helmut Weber

Hi Paul,

hmm.....,
could give me a link to a website
you are copying and want to clean?

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
G

Graham Mayor

Dim oShape As InlineShapes
Set oShape = ActiveDocument.InlineShapes
For i = oShape.Count To 1 Step -1
If oShape(i).Type = 10 Then oShape(i).Delete
Next i

will remove the yellow java script boxes.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Paul Martin

That's fantastic, Graham. Many thanks. I've modified it as follows:

Dim ishp As InlineShape

For Each ishp In ActiveDocument.InlineShapes
If ishp.Type = wdInlineShapeScriptAnchor Then
ishp.Delete
End If
Next ishp

Paul
 
P

Paul Martin

Another small request for basic info (pardon my ignorance):

Wherever a script object is located, I want to delete the space
before, a line break after and insert ", " so that the text on two
lines is now on one line, separated by the ", ". Can someone
suggest the code to achieve this.

Thanks in advance

Paul
 
G

Graham Mayor

To take your request literally

Dim oShape As InlineShapes
Set oShape = ActiveDocument.InlineShapes
For i = oShape.Count To 1 Step -1
If oShape(i).Type = 10 Then
oShape(i).Select
With Selection
.Delete
.TypeBackspace
.TypeText Text:=", "
.Delete wdCharacter, 1
End With
End If
Next i

But what about the shapes in the table?


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Paul Martin

Graham

I only copy as far as the table row with the dates so the script
objects below that aren't an issue. Thanks again for your help.

Regards

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top