locked
Inserting word watermark RRS feed

  • Question

  • User1237844216 posted

                        With oWordDoc
                            .Activate()
                            .Sections(1).Range.Select()
                            .ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
                            .Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect1, "UNCONTROLLED", "Calibri", 1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, 0, 0).Select()
                            .Selection.ShapeRange.Name = "PowerPlusWaterMarkObject762362640"
                            .Selection.ShapeRange.TextEffect.NormalizedHeight = False
                            .Selection.ShapeRange.Line.Visible = False
                            .Selection.ShapeRange.Fill.Visible = True
                            .Selection.ShapeRange.Fill.Solid()
                            .Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)
                            .Selection.ShapeRange.Fill.Transparency = 0.5
                            .Selection.ShapeRange.Rotation = 315
                            .Selection.ShapeRange.LockAspectRatio = True
                            .Selection.ShapeRange.Height = 131.76
                            .Selection.ShapeRange.Width = 527.76
                            .Selection.ShapeRange.WrapFormat.AllowOverlap = True
                            .Selection.ShapeRange.WrapFormat.Side = 3
                            .Selection.ShapeRange.WrapFormat.Type = 3
                            .Selection.ShapeRange.RelativeHorizontalPosition = 0
                            .Selection.ShapeRange.RelativeVerticalPosition = 0
                            .Selection.ShapeRange.Left = -999995
                            .Selection.ShapeRange.Top = -999995
                            .ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument
                            .Save()
                        End With

    It throws at this line...

    .Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect1, "UNCONTROLLED", "Calibri", 1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, 0, 0).Select()

    This is the error...

    System.MissingMemberException was unhandled by user code
      Message=Public member 'Selection' on type 'DocumentClass' not found.
      Source=Microsoft.VisualBasic
      StackTrace:
           at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
           at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
           at docview.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\peternorth\My Documents\Visual Studio 2010\WebSites\sitecweb\docview.aspx.vb:line 57
           at System.Web.UI.Control.OnLoad(EventArgs e)
           at System.Web.UI.Control.LoadRecursive()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:

    Thursday, March 8, 2012 10:50 AM

Answers

All replies

  • User-1831219222 posted

    change the addTextEffect line to

     .Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect1, "UNCONTROLLED", "Calibri", 1, False,False, 0, 0).Select
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    

    see this great working example:

    http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/0c912774-c55d-4fa0-a22a-50ad3ce0e0d6/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 8, 2012 2:49 PM
  • User1237844216 posted

    Thanks for that.  Gave me some clues.

    Got it all working now...

    Dim fileName As Object = downloadedx
                        Dim oWordApp As New Word.ApplicationClass()
                        Dim [readOnly] As Object = False
                        Dim isVisible As Object = True
                        Dim missing As Object = System.Reflection.Missing.Value
    
    
                        Dim oWordDoc As Word.Document = oWordApp.Documents.Open(fileName, missing, [readOnly], missing, missing, missing, _
                         missing, missing, missing, missing, missing, isVisible, _
                         missing, missing, missing)
    
                        With oWordDoc
                            .Activate()
                            .Sections(1).Range.Select()
                            .ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
                            .ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect1, "UNCONTROLLED", "Calibri", 1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, 0, 0).Select()
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Name = "762362640"
                            .ActiveWindow.ActivePane.Selection.ShapeRange.TextEffect.NormalizedHeight = False
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Line.Visible = False
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Fill.Visible = True
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Fill.Solid()
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Fill.Transparency = 0.5
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Rotation = 315
                            .ActiveWindow.ActivePane.Selection.ShapeRange.LockAspectRatio = True
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Height = 131.76
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Width = 527.76
                            .ActiveWindow.ActivePane.Selection.ShapeRange.WrapFormat.AllowOverlap = True
                            .ActiveWindow.ActivePane.Selection.ShapeRange.WrapFormat.Side = 3
                            .ActiveWindow.ActivePane.Selection.ShapeRange.WrapFormat.Type = 3
                            .ActiveWindow.ActivePane.Selection.ShapeRange.RelativeHorizontalPosition = 0
                            .ActiveWindow.ActivePane.Selection.ShapeRange.RelativeVerticalPosition = 0
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Left = -999995
                            .ActiveWindow.ActivePane.Selection.ShapeRange.Top = -999995
                            .ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument
                            .ActiveWindow.Document.Save()
                        End With
    Friday, March 9, 2012 3:28 AM