BrotherDude
Board Regular
- Joined
- Sep 11, 2013
- Messages
- 50
Hello all,
I have a project where I am exporting an excel table to word and trying to add a watermark. Everything is working except for the watermark. When I put the watermark code in a Word module it works however in excel I'm getting runtime errors. I've added the Word library to so I'm not sure what I'm doing wrong. Is this one of those early vs late binding situations?
I have a project where I am exporting an excel table to word and trying to add a watermark. Everything is working except for the watermark. When I put the watermark code in a Word module it works however in excel I'm getting runtime errors. I've added the Word library to so I'm not sure what I'm doing wrong. Is this one of those early vs late binding situations?
Code:
Sub Watermark()
Dim appWD As Object
Set appWD = CreateObject("Word.Application")
'Dim appDoc As Object
'Set appDoc = appWD.Documents.Add
With appWD
'opens new Word Doc
.Documents.Add
.Visible = True
End With
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''Found the code below online but I'm getting runtime error 438 when running out of Excel VBE, works in MS Word VBE
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim strWMName As String
'selects all the sheets
ActiveDocument.Sections(1).Range.Select
strWMName = ActiveDocument.Sections(1).Index
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader ''''''ERROR""""" Runtime Error 438
'Change the text for your watermark here
Selection.HeaderFooter.Shapes.AddTextEffect(msoTextEffect1, _ '''''ERROR"""""Runtime Error 438
"DRAFT", "Arial", 1, False, False, 0, 0).Select
With Selection.ShapeRange
.Name = strWMName
.TextEffect.NormalizedHeight = False
.Line.Visible = False
With .Fill
.Visible = True
.Solid
.ForeColor.RGB = Gray
.Transparency = 0.5
End With
.Rotation = 315
.LockAspectRatio = True
.Height = InchesToPoints(2.42)
.Width = InchesToPoints(6.04)
With .WrapFormat
.AllowOverlap = True
.Side = wdWrapNone
.Type = 3
End With
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
'If using Word 2000 you may need to comment the 2
'lines above and uncomment the 2 below.
' .RelativeHorizontalPosition = wdRelativeVerticalPositionPage
' .RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''Errors are above
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Documents.Save NoPrompt:=True, OriginalFormat:=wdOriginalDocumentFormat
'Kill the object
appWD.Quit False
Set appWD = Nothing
End Sub