Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 04-15-2022, 04:13 PM
macropod's Avatar
macropod macropod is offline Copy paste highlighted text to another doc Windows 10 Copy paste highlighted text to another doc 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


Quote:
Originally Posted by burniksapwet View Post
I need it to be in a macro because the next step is creating a .bat for it that will automate doing it for multiple documents inside a folder. Thank you.
To process all documents in a folder, you'd use a macro (not a .bat file) like:
Code:
Sub ProcessDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
Do While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With ActiveDocument 'wdDoc
      .ActiveWindow.View.ShowHiddenText = True
      With .Range
        .Font.Hidden = True
        With .Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Replacement.Font.Hidden = False
          .Forward = True
          .Wrap = wdFindContinue
          .Format = True
          .Highlight = True
          .MatchWildcards = True
          .Text = ""
          .Replacement.Text = "^&^p"
          .Execute Replace:=wdReplaceAll
          .Text = "[^13]{2,}"
          .Replacement.Text = "^p"
          .Execute Replace:=wdReplaceAll
        End With
        .Copy
        .PasteSpecial DataType:=wdPasteText
      End With
      .Range.Font.Hidden = False
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Loop
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 04-15-2022, 10:07 PM
burniksapwet burniksapwet is offline Copy paste highlighted text to another doc Windows 10 Copy paste highlighted text to another doc Office 2007
Novice
 
Join Date: Jan 2022
Posts: 6
burniksapwet is on a distinguished road
Default

Thank you. It would work for the first document but then it would get an error. This is the string it is highlighting that is saying is the error.
.PasteSpecial DataType:=wdPasteText
Reply With Quote
  #18  
Old 04-16-2022, 06:45 AM
macropod's Avatar
macropod macropod is offline Copy paste highlighted text to another doc Windows 10 Copy paste highlighted text to another doc 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

What error?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Text Twice to Paste into word Albundy Word 2 09-02-2016 12:59 PM
Copy paste highlighted text to another doc Find & selected paras with highlighted text & copy to clipboard marceepoo Word VBA 1 09-14-2012 08:20 PM
Copy paste highlighted text to another doc Table copy/paste suddenly text-only mjcoon Word Tables 20 04-28-2012 08:53 PM
Can't copy/cut and paste text in Word 2002 mmiller751 Word 0 04-17-2012 02:55 PM
Losing Text box data when copy and paste Spay Excel 0 03-15-2011 07:18 AM

Other Forums: Access Forums

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