#1
|
|||
|
|||
Need Help With Find and Replace Wildcard
I have the below information in a document.
ACA-03380 ACA-03381 ACA-03382 ACA-03383 ACA-03384 I'm looking for a wildcard that will help me insert a list of sequential numbers starting with 1 using a input box. The desired output is shown below. 1. ACA-03380 2. ACA-03381 3. ACA-03382 4. ACA-03383 5. ACA-03384 As always thank you in advance for your support. |
#2
|
|||
|
|||
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range Dim lngIndex As Long lngIndex = 1 Set oRng = ActiveDocument.Range With oRng.Find .Text = "ACA-^#^#^#^#^#" While .Execute oRng.InsertBefore lngIndex & ". " lngIndex = lngIndex + 1 oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Hi Greg,
Thank you for the code. It does the job. Great!!! I appreciate it. |
#4
|
|||
|
|||
Extracting Data From A Document To Excel
A while back I was given a solution to my original request. Now, I'm trying to see if I can get help with my new request.
I have several files with a combination of letters and numbers. They look like this: 1. ACA-03380 2. ACA-03390 3. ACA-03395 4. ACA-03450 5. ACA-03684 ... 85. ACA-05784 ... 92. ACA-08898 I would like to see if the above information could be extracted or copy to the bottom of the same document or if they can be exported to an excel file. My preference will be to Excel. Thanks in advanced. Cheers! Last edited by macropod; 10-13-2015 at 09:30 AM. Reason: Deleted unnecessary quote of entire previous posts in same thread... |
#5
|
||||
|
||||
Why do you need a macro? Can't you just copy the data and paste them into Excel? Aside from which, you haven't told us whether you want to use an existing workbook or a new one, etc.
PS: Unnecessarily quoting entire posts just adds clutter.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Thank you Paul for your response. I will try not to clutter again.
So going back to your reply, I don't know if a macro if needed or not. I can't copy and paste them into Excel because in between the numbers I have information. My option (if available) is to have exported into a new Excel document. Here is how the information looks like after the ACA-XXXXX numbers (listed from 1 to 3). Thanks! 1d. ACA-03626 Which of the follsosdwing procedures XXXXwoSSSSuld an entity most lSSSSSikely incSSSSlude in its disaster recovery plan? a. xxxCcocncvcecrctc a. b. Maintssfadisns sas stsrojan horse program to prevent illicit activity. c. Devselop an auxiliasfdsssbsrsy sspsty. d. Stodrse dupsddslsiscsastfes ffdcfof. Answer: D Answer (A) xxxx. Answer (B) xxxx. Answer (C) xxxx. Answer (D} xxxx. 2. ACA-03631 Which of the follsosdwing procedures XXXXwoSSSSuld an entity most lSSSSSikely incSSSSlude in its disaster recovery plan? a. xxxCcocncvcecrctc a. b. Maintssfadisns sas stsrojan horse program to prevent illicit activity. c. Devselop an auxiliasfdsssbsrsy sspsty. d. Stodrse dupsddslsiscsastfes ffdcfof. Answer: D Answer (A) xxxx. Answer (B) xxxx. Answer (C) xxxx. Answer (D} xxxx. 3. ACA-Which of the follsosdwing procedures XXXXwoSSSSuld an entity most lSSSSSikely incSSSSlude in its disaster recovery plan? a. xxxCcocncvcecrctc a. b. Maintssfadisns sas stsrojan horse program to prevent illicit activity. c. Devselop an auxiliasfdsssbsrsy sspsty. d. Stodrse dupsddslsiscsastfes ffdcfof. Answer: D Answer (A) xxxx. Answer (B) xxxx. Answer (C) xxxx. Answer (D} xxxx. |
#7
|
||||
|
||||
Your example is confusing. Do some of these numbered pargraphs have content between the number and ACA as your "1d. ACA-03626" shows?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Quote:
But there is (are) content between the listed numbers with their associated ACA-XXXXX (number) 1. ACA-03626 2. ACA-03656 3. ACA-03697 .. 95. ACA-08566 .. 125. ACA-09633 Hope this help. Thanks! |
#9
|
||||
|
||||
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] |
#10
|
|||
|
|||
Thanks! The execution of the code is really fast.
Working great! Thank you for your support. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wildcard Find and Replace anomaly | BruceM | Word | 3 | 07-10-2015 04:33 AM |
New Find/Replace Wildcard Needed | rsrasc | Word VBA | 2 | 11-11-2014 09:46 AM |
Find/Replace Wildcard Needed | rsrasc | Word VBA | 4 | 11-11-2014 08:28 AM |
Wildcard Find and Replace | Ulodesk | Word | 1 | 06-23-2014 10:26 AM |
Need help using WildCard Find & Replace | Cayce | Word | 1 | 06-09-2014 04:17 PM |