Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2022, 01:25 PM
effimera effimera is offline VBA for duplicating text after slash Windows 10 VBA for duplicating text after slash Office 2019
Novice
VBA for duplicating text after slash
 
Join Date: Jun 2021
Posts: 8
effimera is on a distinguished road
Default VBA for duplicating text after slash

Hi there,

I wonder, in MS Word, if is possible to create a macro that can put a slash after every sentence (let's say right before a paragraph symbol) and at the same time duplicate the sentence (the whole sentence without the slash at its end). Is it even possible in text boxes and tables too?


I also tried to make use of regular expressions; unfortunately, it didn't work for text boxes and tables. I need to maintain the original formatting so I think the VBA might help.

For example:

Original formulation:
If you chose this option on your enrollment form, please allow up to 45 days for the premium withdrawal to be set up.

Target reconstruction should look like this:
If you chose this option on your enrollment form, please allow up to 45 days for the premium withdrawal to be set up./If you chose this option on your enrollment form, please allow up to 45 days for the premium withdrawal to be set up.

The point is that, upon running VBA, I need to hide the first (original) part in order to import and translate the file in a CAT tool with the target file being then exported and the hidden text deactivated; thus resulting in a bilingual document (with two languages divided by a slash).
Please is there any way out?

Thank you for any idea.

Irene
Reply With Quote
  #2  
Old 09-20-2022, 03:14 PM
macropod's Avatar
macropod macropod is offline VBA for duplicating text after slash Windows 10 VBA for duplicating text after slash Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I doubt VBA would be much help with this, since VBA has no idea what a grammatical sentence is. For example, consider the following:
Quote:
Mr. Smith spent $1,234.56 at Dr. John's Grocery Store, to buy: 10.25kg of potatoes; 10kg of avocados; and 15.1kg of Mrs. Green's Mt. Pleasant macadamia nuts.
For you and me, that would count as one sentence; for VBA it counts as 5 sentences.

You can achieve most of what you want with a wildcard Find/Replace, where:
Find = ([!.\!\?;:]@[.\!\?;:])([ ^13])
Replace = \1/\1\2

Regarding tables, you might need to ensure the final sentence has the appropriate punctuation and there's at least a space character before the end-of-cell marker. Textbox final sentences would also require the appropriate punctuation.

With lists, the 'and' or 'or' following the penultimate entry won't be duplicated, nor will final entries followed by a comma.

Sentences containing decimal numbers will also trip up the Find/Replace, with only the portion following the decimal being duplicated.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-20-2022, 03:45 PM
Guessed's Avatar
Guessed Guessed is offline VBA for duplicating text after slash Windows 10 VBA for duplicating text after slash Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
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

It is pretty straightforward if you ignore sentences and do this at the paragraph level instead.

I would avoid a single slash as your language divider because it is reasonably likely to occur in the text itself and confuse your handling of the paragraphs. I would use a pair of them since it is way less likely to be part of the text being translated.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
bilingual translation, duplicate, slash



Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicating dropdown box but also removing text in paragraphs when option is not selected arty1 Word VBA 2 08-08-2020 09:30 PM
VBA for duplicating text after slash Help duplicating text box tabbakh Word 2 11-29-2017 02:36 PM
Auto Duplicating Text in Doc strodden Word VBA 4 11-03-2017 11:10 PM
Showing and hiding sections, duplicating text, etc. Networkrail Word 1 07-11-2017 02:14 PM
A slash shows up before bookmarks Hunter Word 0 03-07-2010 05:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:09 AM.


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