View Single Post
 
Old 03-09-2024, 11:02 AM
ctviggen ctviggen is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

Thank you for that, and sorry for my delay in responding. I often only have weekends to work on this, then not much time.

Anyway, I have a variable oRng, which I did not discuss. After adding text and pasting text in, oRng has the range of the text that has been added and pasted.

So, I modified your code to be "oRng.paragraphs(2).Range.Words(1).Delete".

This worked...a bit.

We're using numbered paragraphs, my test document has something like "[00344](tab)", the numbered paragraph of [00344] followed by a tab character, then it's blank. I add some text, add a new paragraph, then paste selected text in and manipulate it. After doing this without the code above:

[00344](tab)Text I added
[00345](tab)[00345] Beginning of what was pasted in...

The "[00345]" is repeated for some reason. Only happens here. All the following paragraphs are fine.

If I use the "oRng.paragraphs(2).Range.Words(1).Delete" to delete the first word of the second paragraph, this is what happens:


[00344](tab)Text I added
[00345](tab)00345] Beginning of what was pasted in...


The beginning bracket [ is removed. If I attempt to delete the second "word" with "oRng.paragraphs(2).Range.Words(2).Delete", I get the following:


[00344](tab)Text I added
[00345](tab)00345 Beginning of what was pasted in...

I have deleted the beginning bracket [ and the ending bracket ], but not the "word" 00345.

Maybe the "00345" isn't a "word"? But it seems to be just numbers that are bold (because our paragraph numbering is bold). I can manually delete this with no issues. I tried (re)applying the style to that paragraph, nothing happens.

I could possibly delete by characters, so I tried the following:

Code:
     Dim tRng As Word.Range
     Set rTng = oRng.paragraphs(2).Range
     tRng.Collapse Direction:=wdCollapseStart
      tRng.Delete (wdCharacter,8)

But I can't get the syntax of the last part correct. (The code above generates an error.) To me, this looks like "expression.Delete([Unit], [Count])", which is here: Range.Delete method (Word) | Microsoft Learn

Unfortunately, there's no example there of using a Unit, Count. I'm at a loss as to how to delete 8 characters.
Reply With Quote