Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2016, 11:24 AM
Ulodesk Ulodesk is offline Fix for a replacement macro Windows 7 64bit Fix for a replacement macro Office 2013
Word 2013 Expert Cert
Fix for a replacement macro
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Fix for a replacement macro

I thought I might be able to patch this recorded macro, but I simply don't know how.


This is a simple, two-part operation for altering a received Word text document with a styled paragraph indent, so that the indent is removed and a tab is inserted in its place. This is needed prior to pasting the text into ancient mainframe computer documents that require the hard return and subsequent tab to make paragraphs intelligibly separate without an extra line space.

I recorded the macro, which selects everything, changes the first-line indent to 0, replaces every hard return with another followed by a tab, and returns the cursor to the top. I then stripped out all of what appeared to be unnecessary parameters dealing with formatting. The result, however, adds a blank paragraph with a tab at the end of the document, while failing to insert a tab in the first paragraph.
Code:
Sub Macro2()
'
' Macro2 Macro
'
'
    Selection.WholeStory
    With Selection.ParagraphFormat
        .FirstLineIndent = InchesToPoints(0)
    End With
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^13"
        .Replacement.Text = "^p^t"
        .Forward = True
        .Wrap = wdFindAsk
        
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    
End Sub
The problem will undoubtedly be obvious to any coder.
Thanks in advance.
Reply With Quote
  #2  
Old 03-14-2016, 04:13 PM
macropod's Avatar
macropod macropod is offline Fix for a replacement macro Windows 7 64bit Fix for a replacement macro Office 2010 32bit
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

The problem is that you're working with paragraph breaks and inserting tabs after them, rather than working with paragraphs and inserting tabs before them. Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[!^13]@^13"
    .Replacement.Text = "^t^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-15-2016, 06:14 AM
Ulodesk Ulodesk is offline Fix for a replacement macro Windows 7 64bit Fix for a replacement macro Office 2013
Word 2013 Expert Cert
Fix for a replacement macro
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default

Thank you, Paul. From my previous effort, I figured out how to add the first-line indent removal command at the beginning of the macro. Works like a charm.
Best,
Philip
Reply With Quote
Reply

Tags
recorded macro failure, replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell replacement? lily Excel 1 06-07-2015 07:20 PM
Fix for a replacement macro Word Replacement Option mattyra Word 7 02-11-2015 11:13 PM
Fix for a replacement macro Automatic Words replacement psychologist Word VBA 3 11-22-2014 11:40 AM
Replacement lostsoul62 Excel 0 04-14-2012 10:07 AM
Replacement Software hirize Office 0 08-28-2008 02:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:31 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