Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:05:46+00:00 2026-05-26T05:05:46+00:00

I have the pleasure to write some code that moves around stuff in an

  • 0

I have the pleasure to write some code that moves around stuff in an Office XP environment. I’ve referenced the OfficeXP Interop Assemblies and written code to Search/Replace stuff. That works fine. Now I need to delete Text around a Bookmark and i keep getting Exceptions thrown at me.

Here is some of the code:

            object units = WdUnits.wdLine;
            object lines = 2;
            object extend = WdMovementType.wdExtend;

            object bookmarkName = "Bank1";
            var bm = doc.Bookmarks;
            var bm1 = doc.Bookmarks.get_Item(bookmarkName);
            var ra = bm1.Range;

            ra.Delete(ref units, ref lines);

The last line is where i get a “Wrong Parameter” Exception. Looking at the Definition in the MSDN I kind of think I’m right. But obviously I’m not. Hope you guys can help me out here.

Update: ok, i see. Using the Delete method on the Range object i can only use wdWord as a Parameter. I’d like to change my question now: what i do want to do is delete two lines starting from the bookmark. How would i do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:05:47+00:00Added an answer on May 26, 2026 at 5:05 am

    Range objects in Word are not “line oriented”, they don’t allow line operations, only paragraph operations. However, selections allow line operations. The current selection is not a property of the word document, but of the word application object. Here is some VBA code which does essentially what you try, I think you can easily port this to C#:

    Dim rng As Range
    Dim doc As Document
    Set doc = ActiveDocument
    Set rng = doc.Bookmarks("BM").Range
    
    Dim s As Long, e As Long
    rng.Select
    s = Application.Selection.Start
    e = Application.Selection.Next(wdLine, 1).End
    
    Application.Selection.SetRange s, e
    Application.Selection.Delete  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working for some code with bxslider because I have many large images,
I have some word templates(dot/dotx) files that contain xml tags along with plain text.
Quick question, looking for some recommendations. I have a site that will be requesting
I have written presumably some of the first code to modify the memory of
Have some dates in my local Oracle 11g database that are in this format:
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have had to write my first proper multithreaded coded recently, and realised just how
Greetings, I have a problem which would seem to involve some kind of z-index
I am creating a survey form that needs to have each question and set
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.