![]() |
|
|
|
#1
|
|||
|
|||
|
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. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Deleting all text from a slide pack without deleting the formatting | redordead2389 | PowerPoint | 0 | 05-31-2023 06:50 AM |
Word macro for deleting a line that starts with a specific character + deleting the line before
|
eduardb | Word | 1 | 08-10-2022 03:17 AM |
| Inserting text from a Userform into a Field in a paragraph in a paragraph in a word document | storemaz | Word VBA | 1 | 03-13-2020 08:11 AM |
Deleting paragraph commands
|
afndst | Word VBA | 2 | 12-30-2015 02:07 AM |
Deleting a script in an equation without deleting the whole term
|
allankey | Word | 1 | 02-15-2014 07:09 AM |