Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-13-2015, 01:52 PM
macropod's Avatar
macropod macropod is offline Need Help With Find and Replace Wildcard Windows 7 64bit Need Help With Find and Replace Wildcard Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Try:


Code:
Sub ExportData()
Dim StrData As String, StrTmp As String, i As Long
Dim xlApp As Object, xlWkBk As Object
With ActiveDocument.Range
  .InsertBefore vbCr
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13[0-9]{1,}. ACA-[0-9]{5}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    StrData = StrData & .Text
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
  Undo 1
End With
' Test whether Excel is already running.
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
'Start Excel if it isn't running
If xlApp Is Nothing Then
  Set xlApp = CreateObject("Excel.Application")
  If xlApp Is Nothing Then
    MsgBox "Can't start Excel.", vbExclamation
    Exit Sub
  End If
End If
On Error GoTo 0
With xlApp
  Set xlWkBk = .Workbooks.Add
  ' Update the workbook.
  With xlWkBk.Worksheets(1)
    For i = 1 To UBound(Split(StrData, vbCr))
      .Cells(i, 1).Value = Split(StrData, vbCr)(i)
    Next
  End With
  ' Tell the user we're done.
  MsgBox "Data extraction finished.", vbOKOnly
  ' Switch to the Excel workbook
  .Visible = True
End With
' Release object memory
Set xlWkBk = Nothing: Set xlApp = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 10-13-2015, 02:37 PM
rsrasc rsrasc is offline Need Help With Find and Replace Wildcard Windows 7 64bit Need Help With Find and Replace Wildcard Office 2010 64bit
Competent Performer
Need Help With Find and Replace Wildcard
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Thanks! The execution of the code is really fast.


Working great!


Thank you for your support.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help With Find and Replace Wildcard Wildcard Find and Replace anomaly BruceM Word 3 07-10-2015 04:33 AM
Need Help With Find and Replace Wildcard New Find/Replace Wildcard Needed rsrasc Word VBA 2 11-11-2014 09:46 AM
Need Help With Find and Replace Wildcard Find/Replace Wildcard Needed rsrasc Word VBA 4 11-11-2014 08:28 AM
Need Help With Find and Replace Wildcard Wildcard Find and Replace Ulodesk Word 1 06-23-2014 10:26 AM
Need Help With Find and Replace Wildcard Need help using WildCard Find & Replace Cayce Word 1 06-09-2014 04:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:44 AM.


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