Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2023, 06:59 AM
ctviggen ctviggen is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Advanced Beginner
Pasting in text like Notepad (not Paste Special)
 
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
  #2  
Old 03-20-2023, 03:14 PM
Guessed's Avatar
Guessed Guessed is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There is an option you can set to either include or exclude the paragraph numbers when pasting as text. You can turn this setting on by going to your Advanced options or add it to the code before your paste command.
Code:
Options.PasteOptionKeepBulletsAndNumbers = True
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-21-2023, 04:06 AM
ChrisGreaves ChrisGreaves is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 97-2003
Novice
 
Join Date: Nov 2022
Location: Bonavista, Newfoundland
Posts: 22
ChrisGreaves is on a distinguished road
Default

Quote:
Originally Posted by ctviggen View Post
I am trying to use VBA for many repetitive tasks performed by our organization.
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.
Hello ctviggen,
Using VBA and Syles is an excellent way to automate boring and repetitive tasks. Congratulations.
Back in 1996 I wrote a Wpord6.0 application, migrated to Word97 then Word2003 called "Document Cleanser". I believe it still works.


My job at that time was to convert thousands of WordPerfect 5.1(DOS) documents to MSWord documents and to clean them along the way.


WP5.1 documents tended to have literal numbering and no styles. Worse numerous temporary editors often copy/pasted gobs of text without re-sequencing the numbers. A nightmare.


Document Cleanser is a rules-based application; a table of rules, controlled by you, determines exactly how the converter works. I have attached two Word2003 document files.


"HardCodedNumberingRules.doc" is a sketch of my ideas about how to resolve a specific hard-code numbering problem


"RulesTable20050126.doc" is a sample rules table, possibly related to my ideas outlined in "HardCodedNumberingRules.doc"



Do not be overwhelmed by the size or apparent gobbledygook of the rules table; they grow in chunks as you test new rules and add them in. And remember this is for batches of 10,000 documents at a time.


Notice that the "Find" and "Replace" columns look suspiciously like the Special command button in MSWord's Find/replace dialogue box. (grin)


Rules (34) through (62) change hard-coded numbers to simple paragraphs in a List Outline style. You can, of course, Replace with whatever text you choose and whatever style you possess.


Rules (86) through (92) convert fixed local-formatting to character-style formatting.


If you think that this sort of approach might solve your problem let me know and we'll talk. The package is free and includes many sample rules tables and an eight-page User Guide.


I can't remember whether the code to loop through 10,000 documents is included, but I'll have a look later. It is spinning around here somewhere.

Cheers, Chris
Attached Files
File Type: doc HardCodedNumberingRules.doc (34.0 KB, 0 views)
File Type: doc RulesTable20050126.doc (249.5 KB, 0 views)
Reply With Quote
  #4  
Old 03-25-2023, 06:52 AM
ctviggen ctviggen is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Advanced Beginner
Pasting in text like Notepad (not Paste Special)
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

Thank you both. Sorry for my delay in responding. This is one of many macros I'm working on. I have a list of macros that would help me only or help a lot of us in my small company. The macro for this thread is to help all of us, but I went back to working on macros that will only help me.



I've rotated back to this macro, though.



Once I implement this one again, I'll report back with what worked.


Thank you again.
Reply With Quote
  #5  
Old 03-26-2023, 03:24 AM
ctviggen ctviggen is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Advanced Beginner
Pasting in text like Notepad (not Paste Special)
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

For me, this does not work, in that the numbered list of the style that I copy does not retain the number when pasted:


Code:
    Set oRng = Selection.Range
    Options.PasteOptionKeepBulletsAndNumbers = True
     oRng.PasteSpecial DataType:=wdPasteText
It seems like it should work, but it does not. In other words, when I copy:
1. Some text...
When I paste using the above code, what gets pasted in is:
Some text...

So, that means I have to add back in the numbering.
Reply With Quote
  #6  
Old 03-27-2023, 10:25 PM
Guessed's Avatar
Guessed Guessed is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

When testing, did your clipboard include the paragraph mark at the end of that autonumbered paragraph?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 03-28-2023, 09:50 AM
ctviggen ctviggen is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Advanced Beginner
Pasting in text like Notepad (not Paste Special)
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

Yes, what it looks like is the following (where the [] indicate hidden characters), and this is for this particular configuration, which a lot of us use:



1.[tab]Some text[paragraph mark][indented according to style] More text, no period[paragraph mark][indented according to style] More text, ends in period[paragraph mark]

[indented according to style][paragraph mark]


2.[tab]Some text[paragraph mark][indented according to style] More text, no period[paragraph mark][indented according to style] More text, ends in period[paragraph mark][indented according to style][paragraph mark]
...


That is, each "chunk" of text starts with a number, then a tab, then some text, then goes to a different style for one or multiple lines/paragraphs, then a blank line, then restarts with a new number. The numbers are in order, starting with 1. This is repeated typically from 20 - 60+ times.


When I use Notepad, the numbers are there.


I typically do this manually. I copy all these "chunks", paste in using Pure Text, which is a program that does what Notepad does, add in "Example " before "1.", highlight everything, search for two paragraphs marks in a row, replace with a paragraph mark then "Example ", and this works perfectly. It's just I have other searches and replacing to do, and do this 100+ times per year. I could change from minutes each time to seconds if I can create a macro.



I can do this without the numbers, but then I have to count the number of "chunks", and figure out how to add in numbers along with the text "Example ". It's possible, and I'm sure I'll do this -- I've gotten a lot closer. It just takes a lot more time than if the numbers were already there.
Reply With Quote
  #8  
Old 03-28-2023, 10:27 PM
Guessed's Avatar
Guessed Guessed is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I assume you are transferring the content from a different Word document? If you are having problems retaining the numbering then you can run a macro on the source to convert the numbers to hard-coded.

If you post sample source and target docs we can work out how to code it to improve the user process.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 03-29-2023, 07:48 AM
ctviggen ctviggen is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Advanced Beginner
Pasting in text like Notepad (not Paste Special)
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

Thank you.



No, I'm actually copying from one part of a document to another. In my line of work, we have documents that have different sections. Often, we copy from one section (which has the numbering scheme I showed above) to another section (with a "normal" paragraph-type scheme), then manipulate what we just copied.



So, think of the numbering/paragraph scheme as being in one section of a document. I want to copy that into a different section (with more of a paragraph scheme) of the document, while keeping the numbering, then manipulate the text, multiple times (search and replace multiple different items).



Does this make sense and would it be useful to have an example document?
Reply With Quote
  #10  
Old 03-30-2023, 02:30 PM
ctviggen ctviggen is offline Pasting in text like Notepad (not Paste Special) Windows 10 Pasting in text like Notepad (not Paste Special) Office 2016
Advanced Beginner
Pasting in text like Notepad (not Paste Special)
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

I figured it out, with help. Here's the code I needed, before I pasted the already-copied material into the document:


Code:
oRng.ListFormat.ConvertNumbersToText wdNumberParagraph

This comes from here:



Copy Text and Retain Numbers When Pasting – Word Macros and Tips – Work Smarter and Save Time in Word


I only needed the single line of code, though.


Other parts don't work, but this saves me tons of coding.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word SMehta Word VBA 27 02-03-2021 03:34 AM
Pasting in text like Notepad (not Paste Special) Copy text with tab at start of line and paste to Notepad JohnTurnbull Word 5 08-27-2017 11:17 PM
need a shortcut for paste special link unformatted text noetic76 Word VBA 2 06-29-2014 06:40 PM
Pasting in text like Notepad (not Paste Special) Paste Special: Copy and Paste Formatting Only? tinfanide Word 6 03-06-2013 12:21 AM
Pasting in text like Notepad (not Paste Special) Paste Special Unformatted Text kenwpaul Office 2 02-25-2011 04:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft