Answered by:
Run-time error '-2147024809 (80070057)'

Question
-
Hi guys,
I am a little bit stuck on how to get round this problem. I am creating a macro to insert a watermark, and I am using Visual Basic to create this macro on Microsoft Word 2010, but I keep getting an error message saying:
Run-time error '-2147024809 (80070057)'
The item with the specific name wasn't found.
I have copied and pasted the code below. and when I click debug, the code it highlights is: Selection.HeaderFooter.Shapes("WordPictureWatermar k102522967").Select <- 3rd line down when code starts
-------------------------------------------------------------------------------
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("WordPictureWatermar k102522967").Select
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName: = _
"G:\A levels\AS ICT Folders\IT2 - PRACTICAL\Task 2 Automated Doc\watermarkimage.jpg" _
, LinkToFile:=False, SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "WordPictureWatermark102632823"
Selection.ShapeRange.PictureFormat.Brightness = 0.85
Selection.ShapeRange.PictureFormat.Contrast = 0.15
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = CentimetersToPoints(19.5)
Selection.ShapeRange.Width = CentimetersToPoints(18.45)
Selection.ShapeRange.WrapFormat.AllowOverlap = True
Selection.ShapeRange.WrapFormat.Side = wdWrapNone
Selection.ShapeRange.WrapFormat.Type = 3
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeVerticalPositionMargin
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionMargin
Selection.ShapeRange.Left = wdShapeCenter
Selection.ShapeRange.Top = wdShapeCenter
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
--------------------------------------------------------------------
I have already tried deleting the code: Selection.HeaderFooter.Shapes("WordPictureWatermar k102522967").Select
Selection.Delete
...but it just keeps highlighting the line below for all of the code and soon I am left with no code lol.
Can someone please tell me how to resolve this issue?
Thanks
GameiTuesday, March 12, 2013 4:11 PM
Answers
-
To add a watermark, you need to delete whatever watermark is already there. Did you try the code I posted?
Cheers
Paul Edstein
[MS MVP - Word]- Marked as answer by Jaynet Zhang Wednesday, March 27, 2013 1:30 AM
Wednesday, March 13, 2013 8:55 AM
All replies
-
Cross-posted at: http://www.techsupportforum.com/forums/f57/run-time-error-2147024809-80070057-a-689512.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
In all likelihood, the issue is that you're trying to work with random pre-defined shape names. You also have a space that probably doesn't exist in the shape name you're tring to delete. Try:
Sub Macro1()
Dim Shp As Shape
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
For Each Shp In .Range.ShapeRange
If InStr(Shp.Name, "WordPictureWatermark") > 0 Then Shp.Delete
Next
Set Shp = .Shapes.AddPicture(FileName:= _
"G:\A levels\AS ICT Folders\IT2 - PRACTICAL\Task 2 Automated Doc\watermarkimage.jpg", _
LinkToFile:=False, SaveWithDocument:=True)
With Shp
.PictureFormat.Brightness = 0.85
.PictureFormat.Contrast = 0.15
.LockAspectRatio = True
.Height = CentimetersToPoints(19.5)
.Width = CentimetersToPoints(18.45)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
End With
End SubNote: The above code assumes you're adding the watermark to Word's primary header.
Cheers
Paul Edstein
[MS MVP - Word]- Edited by macropodMVP Wednesday, March 13, 2013 5:45 AM
Wednesday, March 13, 2013 5:44 AM -
ok thanks, but im not meaning to delete the shape/image!
when i recorded the macro, i did not record the shape/image being deleted, it got put in the code automatically. But when I delete the lines (that link to the delete) the line below will be highlights, then the line below and so on (if that makes sense).
Wednesday, March 13, 2013 7:51 AM -
To add a watermark, you need to delete whatever watermark is already there. Did you try the code I posted?
Cheers
Paul Edstein
[MS MVP - Word]- Marked as answer by Jaynet Zhang Wednesday, March 27, 2013 1:30 AM
Wednesday, March 13, 2013 8:55 AM