View Single Post
 
Old 03-20-2023, 06:59 AM
ctviggen ctviggen is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default Pasting in text like Notepad (not Paste Special)

I am trying to use VBA for many repetitive tasks performed by our organization. One of those involves copying and then pasting in text, and then processing that pasted-in text.



The text that we would be copying looks like this:

1. Some text (multiple lines of text, wherein only the first line is numbered)...

2. The text of 1, wherein...(again, only the first line has a number)
We use Word Styles for this:
- The numbered paragraphs are one style
- The non-numbered paragraphs that follow the numbered paragraphs are a different style.



Manually performing this, I typically copy this text, then use a program called Pure Text, which essentially operates as Notepad does: That is, the "1.", "2." that begin the first lines are included.



Thus, when I manually paste this in (using a keystroke devoted to Pure Text), the numbers are there. (I could copy, paste into Notepad, copy all, then paste into Word and get the same result.)



Trying to implement this in VBA, however, if I perform a Paste Special, then Text Only, the numbers are not there. In VBA, this is what I am using:

Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False
This does not paste in the numbers ("1.", "2."...).



Using VBA, is there a way to paste in a way that acts like Notepad does?



If that is not possible, is it possible to access the clipboard (I assume this is where the text is stored before pasting it?) and then get those numbers or otherwise process what is in the clipboard so that I can retain those numbers?


Ideally, I would not use text and would instead convert from one Word style to another. However, not everyone uses the same styles, and I'm concerned the level of programming it would take to operate with different styles would be too complex.



Thank you.
Reply With Quote