A way to bypass the 255 character limit in my code? - excel

I have a Word document where the user will input codes for standard comments, usually using an outline format like bullets 1, a, 2, and 3. The user saves and closes the Word document. Then the user can open a Comments Excel document and click on a button that will ask the user to find which Word document they want to replace the codes (column A) with the Text value (column C) in the Excel document. The code and process work great except when the value exceeds 255 characters, which will happen quite often. I've read about using the clipboard in doing this, but I wasn't sure how to implement it into my existing code. Thank you for any help. Sorry if I am not posting this correctly, new to this forum.
Sample comments in Word:
B401
B402
M317
This is my own comment
P203
Sample in Excel file (each row separated by a comma):
Column A rows- B401, B402, M317, P201, P203
Column B rows- Handrail compliance, Handrail Extensions, HVAC, Water Building, Water System
Column C rows-
Handrails shall comply with section 1014 of the 2015 International Building Code.,
Handrails shall return to a wall guard or walking surface. (See Section 1014.6 of the 2015 International Building Code.),
No HVAC drawings shown; will handle in the field.,
Where water pressure within a building exceeds 80 psi (552 kPa) static, an approved water pressure reducing valve conforming to ASSE 1003 or CSA B356 with strainer shall be installed to reduce the pressure in the building water distribution piping to 80 psi (552 kPa) static or less. Exceptions to this requirement are service lines to sill cocks and outside hydrants, and main supply risers where pressure from the mains is reduced to 80 psi (552 kPa) or less at individual fixtures. (See Section 604.8 of the 2015 International Plumbing Code.),
A water test shall be applied to the drainage system either in its entirety or in sections. If applied to the entire system, all openings in the piping shall be tightly closed, except the highest opening, and the system shall be filled with water to point of overflow. If the system is tested in sections, each opening shall be tightly plugged except the highest openings of the section under test, and each section shall be filled with water, but no section shall be tested with less than a 10-foot (3048 mm) head of water. In testing successive sections, at least the upper 10 feet (3048 mm) of the next preceding section shall be tested so that no joint or pipe in the building, except the uppermost 10 feet (3048 mm) of the system, shall have been submitted to a test of less than a 10-foot (3048 mm) head of water. The water shall be kept in the system, or in the portion under test, for at least 15 minutes before inspection starts. The system shall then be tight at all points. (See Section 312.2 of the 2015 International plumbing Code.) Plastic piping shall not be tested with air. An air test shall be made by forcing air into the system until there is a uniform gauge pressure of 5 pounds per square inch (psi) (34.5 kPa) or sufficient to balance a 10-inch (254 mm) column of mercury. This pressure shall be held for a test period of at least 15 minutes. Any adjustments to the test pressure required because of changes in ambient temperature or the seating of gaskets shall be made prior to the beginning of the test period. (See Section 312.3 of the 2015 International Plumbing Code)
Existing Excel Code that works until the 255 character limit:
Sub Replace()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Add "Word Files", "*.docx; *.docm", 1
.Show
fullpath = .SelectedItems.Item(1)
End With
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim from_text As String, to_text As String
Dim WA As Object
pathh = fullpath
Set WA = CreateObject("Word.Application")
WA.Documents.Open (pathh)
WA.Visible = True
For oCell = 1 To 500
from_text = Sheets("Comments").Range("A" & oCell).Value
to_text = Sheets("Comments").Range("C" & oCell).Value
With WA.ActiveDocument
Set myRange = .Content
With myRange.Find
.Execute FindText:=from_text, ReplaceWith:=to_text, Replace:=1
End With
End With
Next oCell
End Sub

The fault is in the function you are using which can't accept a parameter of the size you want. So, we have to work around it a bit. Try replacing your for loop with this:
For oCell = 1 To 500
from_text = Sheets("Comments").Range("A" & oCell).Value
to_text = Sheets("Comments").Range("C" & oCell).Value
If from_text = "" Then Exit For
WA.Selection.Find.ClearFormatting
WA.Selection.Find.Replacement.ClearFormatting
With WA.Selection.Find
.Text = from_text
.Forward = True
.Wrap = 1
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
IF WA.Selection.Find.Execute Then
WA.Selection = to_text
End If
Next oCell
The goal here is just to use find to select the "from" text, and then assign that selection with the intended "to" text value. This avoids the replace function itself. Tested successfully on my end. The code more closely matches what Word generates in its macro recorder, however some VBA constants have been replaced with numeric values, so buyer beware.
Hope it helps

Related

Location causes incorrect placement of separators in Excel during file import

I import large amounts of data into Excel. These are previously reduced in quantity from 100 Hz to 1 Hz by a third-party program to reduce work and load time. However, during this reduction process, decimal and thousands separators are swapped, probably because the software is designed in a different language.
Original (Example line):
009 090308.510 +2475.77145123 -0091.51682637 070.530 271.89 +0168.67 +0001.13 -8.485680E-04 0.000000 +4.625850E-04 +2.679440E+36 -2.544081E-29 +2.658468E+36
Processed by third party program:
009 090308,510 +2475,77145123 -0091,51682637 070,530 271.89 +00168,67 +001,130 0,000000 -8.485680E-04 +4.625850E-04 +2.679440E+36 -2.544081E-29 +2.658468E+36
As can be seen, some separators are swapped by the program, but others are not. If I now apply my import code to both formats, I get the following results:
Original:
9 90308.51 2475.771 -91.5168 70.53 271.89 168.67 1.13 -8.49E-04 0 4.63E-04 2.68E+36 -2.54E-29 2.66E+36
Processed:
9 90,308,510 247,577,145,123 -9,151,682,637 40,530 271.89 +00168,67 1,130 0,000000 -8.49E-04 4.63E-04 2.68E+36 -2.54E-29 2.66E+36
For understanding here the code for import:
Option Explicit
Public Sub fileImporter()
Dim fDialog As FileDialog
Dim fPath As Variant
Dim FSO
Dim Data
Dim arr, tmp, output
Dim file, fileName As String
Dim x, y As Integer
Dim newSht As Worksheet
Application.ScreenUpdating = False
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = True
.Title = "Please select files to import"
.Filters.Clear
.Filters.Add "VBO Files", "*.vbo" 'VBO Files are opened and handled like Text Files
If .Show = True Then
For Each fPath In .SelectedItems
Set FSO = CreateObject("Scripting.FilesystemObject")
fileName = FSO.GetFilename(fPath)
Set Data = FSO.OpentextFile(fPath)
file = Data.readall
Data.Close
arr = Split(file, vbCrLf)
ReDim output(UBound(arr), 50)
For x = 0 To UBound(arr)
tmp = Split(arr(x), " ")
For y = 0 To UBound(tmp)
output(x, y) = tmp(y)
Next
Next
Set newSht = ActiveWorkbook.Sheets.Add(after:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count))
newSht.Name = fileName
Sheets(fileName).Range("A1").Resize(UBound(output) + 1, UBound(output, 2)) = output
Next
End If
End With
Application.ScreenUpdating = True
End Sub
The record of the processed file is not separated rudimentarily correctly and reasonably. I have also already tried using
With Application
.DecimalSeparator = "."
.ThousandsSeparator = ","
.UseSystemSeparator = False
End With
but that did not work either. Or rather, it changed the separators, but the result stayed the same. The numbers were not separated at the correct places.
I found a similar question here (Importing CSV US formatted numbers in Excel with localisation), which seems to be the same problem. But since the import function in the answer is different from mine, I am not sure how to integrate it properly.
Does someone have a idea? Maybe a way how to preserve the format while or during splitting? Or a better place to integrate the Application.DecimalSeparator argument in the given code?
Thanks for the help!
EDIT:
The problem could be solved by comparing system settings. Apparently, the computer was not provided with the default settings by IT and some settings of the previous owner were still present. These included a partial language change to German, as well as a permanent replacement of the decimal and thousands separators in Excel, instead of using the system separators. After correcting these settings, the program and import works without incorrect separator usage.
You may be able to obtain your desired output using Power Query, available in Windows Excel 2010+ and Office 365 Excel
Data => Get &Transform => From Text/Csv
When the initial dialog opens, ensure Space is selected as the Delimiter
Select Transform Data
Select Home=>Advanced Editor
Replace the code after your Source line with the code below (after Source)
Edit change in swapping algorithm
It appears by examination that
All columns are numeric
Separators are swapped on the columns where there is a comma
All other columns have the separators not swapped
If those assumptions are not correct, some changes may need to occur
If there are swapped and non-swapped values in a single column, I would suggest you develop another method to sample your data, else you would have to check every single cell
M Code edited to implement change in algorithm above
M Code edited to check first 200 table rows for commas instead of just first row
let
Source = Csv.Document(File.Contents("C:\Users\ron\Desktop\decimals.txt"),
[Delimiter=" ", Columns=14, Encoding=1252, QuoteStyle=QuoteStyle.None]),
//Swapped separators = numbers with commas
// check only the first 200 rows, for efficiency
#"Check Table" = Table.Buffer(Table.FirstN(Source, List.Max({Table.RowCount(Source), 200}))),
Swapped = List.Accumulate(Table.ColumnNames(#"Check Table"), {}, (state, current)=>
if List.AnyTrue(List.Transform(Table.Column(#"Check Table", current), each Text.Contains(_,",")))
then state & {current} else state),
notSwapped = List.RemoveMatchingItems(Table.ColumnNames(#"Check Table"),Swapped),
//Set the data types appropriately
#"Type Not Swapped"= Table.TransformColumnTypes(Source,
List.Transform(notSwapped, each {_, type number}),"en-US"),
#"Type Swapped" = Table.TransformColumnTypes(#"Type Not Swapped",
List.Transform(Swapped, each {_, type number}),"da-DK")
in
#"Type Swapped"
Original Data
| 009 | 090308,510 | +2475,77145123 | -0091,51682637 | 070,530 | 271.89 | +00168,67 | +001,130 | 0,000000 | -8.485680E-04 | +4.625850E-04 | +2.679440E+36 | -2.544081E-29 | +2.658468E+36 |
Results

Different appearance in VBA produced sheet with same font and cell attributes

I am trying to automate the preparation of an internal Excel-based report based on a previous template.
The macro creates and fills a new sheet, matching the font name, size, color etc. settings of the template, as well as the row heights - column widths. Despite providing the exact same values for font, height, width etc., the VBA produced sheet's font does not match the original template. I believe the issue can be fixed if we can figure out why the VBA produced text is "pixelated".
As I am not familiar with the file sharing best-practices of SO, I will be including code used to reproduce the new sheet and a comparison of some attributes of the both sheets. I will include a link to the file containing the two sheets in the comments. I believe it may be important to have a copy of the original template to answer this question.
Here is an example of how a cell's properties are changed, pretty basic.
ws.Columns(12).EntireColumn.ColumnWidth = 9.57
ws.Rows(9).EntireRow.RowHeight = 50.25
ws.Cells(9, 12).Font.Name = "Segoe UI"
ws.Cells(9, 12).Font.Size = 11
Here are some properties I compared for the two sheets as I did not know what I was looking for, all are identical for the two sheets.
Range.AddIndent = False
Range.ColumnWidth = 9.57
Range.RowHeight = 50.25
Range.Font.Name = "Segoe UI"
Range.Font.FontStyle = "Regular"
Range.Font.Size = 11
Range.Font.ThemeFont = xlThemeFontNone
Range.Font.ThemeColor = 2
Range.Font.OutlineFont = False
Range.Font.Subscript = False
Range.Font.Superscript = False
Range.Font.Italic = False
Range.HasSpill = False
Range.Phonetics = Nothing
Range.PrefixCharacter = ""
Range.SpillingToRange = Nothing
Range.UseStandardHeight = True
Range.UseStandardWidth = False
Range.WrapText = True
Worksheet.Cells.AddIndent = False
Worksheet.EnableOutlining = False
Worksheet.Outline.AutomaticStyles = False
Worksheet.PageSetup.BottomMargin = 18 'These are different, but did not effect the outcome when equalized
Worksheet.PageSetup.LeftMargin = 50.4 'These are different, but did not effect the outcome when equalized
Worksheet.PageSetup.FooterMargin = 21.6 'These are equal for both
Worksheet.PageSetup.HeaderMargin = 21.6 'These are equal for both
Worksheet.StandardHeight = 16.5 'These are different, yet read-only
Worksheet.StandardWidth = 8.38 'These are different, yet read-only
I know a little HTML/CSS and my guess is despite having the same font families(names), the .woff2 or .eot are different for the two fonts. I have no idea why though.
Painting the target cells using the original template format does the job, as does a copy/pasting strategy, but I am aiming for a clean solution without including the template in the final file and generating the sheets from scratch. I could also change the font family or cell sizes to get an acceptable output, but at this point I wish to explore the reason behind this issue out of curiosity.

Adding Data Label to Excel Chart - Time Consuming

I have a code that adds a data label to the selected point on a chart. The section of code below takes about 4 seconds. And that is too long for the take I am working on. Any ideas?
My computer has reasonable specs. and I am using Office 2013.
Set SRS = ChartObjects.SeriesCollection(Arg1)
If SRS.Points(Arg2).HasDataLabel = False Then
ChartObjects.SeriesCollection(Arg1).Points(Arg2).HasDataLabel = True
ChartObjects.SeriesCollection(Arg1).Points(Arg2).DataLabel.Text = "Case: #" + CStr(CaseCoUnter)
Select Case True
Case Upper
ChartObjects.SeriesCollection(Arg1).Points(Arg2).DataLabel.Position = xlLabelPositionAbove
Case Lower
ChartObjects.SeriesCollection(Arg1).Points(Arg2).DataLabel.Position = xlLabelPositionBelow
End Select
End If
I too have an Intel processor, but at a slightly lower speed of 2.60 GHz, and only 8 GB of RAM. Nevertheless, when I tested your posted code, I clicked on a data point and it added the data label somewhat instantaneously. So if it's taking about 4 seconds for you, it may be because you have other code within the event procedure that is slowing it down. In any case, your code could be re-written as follows...
Set SRS = ChartObjects.SeriesCollection(Arg1)
With SRS.Points(Arg2)
If .HasDataLabel = False Then
.HasDataLabel = True
.DataLabel.Text = "Case: #" + CStr(CaseCoUnter)
Select Case True
Case Upper
.DataLabel.Position = xlLabelPositionAbove
Case Lower
.DataLabel.Position = xlLabelPositionBelow
End Select
End If
End With

Excel - need to extract a machine ID that includes a number in a cell, regardless of its position in sentence

It's my first time posting a question here :)
When exporting data from our enterprise ticketing system, we unfortunately do not have a specific column for a machine ID, but instead have "problem description" column which includes both the short description of the issue and the machine ID. The Machine ID always has numbers, but may contain only numbers or 2-4 letters before the number, with no spaces, examples are:
XK2065
2092
BOZK10625
The number of digits can vary, but is never more that six.
2 examples of the problem description:
1) XK2065 - issue not detected, please investigate.
2) Please investigate why issue was not detected, machine ID is XK2065, ticket number 1425778.
So, the problem is that the unit ID can be located anywhere in the sentence and can also contain only numbers or 2 to 4 letters before the numbers.
Is there a function that can extract the machine ID, regardless of location, along with the beginning letters adjacent to the numbers if it has them? Additional condition I'd like is for a number of digits to be no more than 6, as sometimes ticket numbers may be included which are 7-digit.
A function would be preferable to VBA macro.
Thanks in advance!
This function should do what you need, using regular expression (like #RonRosenfeld suggested):
Function RegExID(str As String) As String
Dim rgx As Object
Set rgx = CreateObject("VBScript.RegExp")
Dim allMatches As Object
With rgx
.Pattern = "\b[A-Z]{0,4}[\d]{4,6}\b"
.Global = True
.ignoreCase = True
.MultiLine = True
End With
Set allMatches = rgx.Execute(str)
For Each Item In allMatches
RegExID = Item.Value
Next
End Function

Extract tables from pdf (to excel), pref. w/ vba

I am trying to extract tables from pdf files with vba and export them to excel. If everything works out the way it should, it should go all automatic. The problem is that the table are not standardized.
This is what I have so far.
VBA (Excel) runs XPDF, and converts all .pdf files found in current folder to a text file.
VBA (Excel) reads through each text file line by line.
And the code:
With New Scripting.FileSystemObject
With .OpenTextFile(strFileName, 1, False, 0)
If Not .AtEndOfStream Then .SkipLine
Do Until .AtEndOfStream
//do something
Loop
End With
End With
This all works great. But now I am getting to the issue of extracting the tables from the text files.
What I am trying to do is VBA to find a string e.g. "Year's Income", and then output the data, after it, into columns. (Until the table ends.)
The first part is not very difficult (find a certain string), but how would I go about the second part. The text file will look like this Pastebin. The problem is that the text is not standardized. Thus for example some tables have 3-year columns (2010 2011 2012) and some only two (or 1), some tables have more spaces between the columnn, and some do not include certain rows (such as Capital Asset, net).
I was thinking about doing something like this but not sure how to go about it in VBA.
Find user defined string. eg. "Table 1: Years' Return."
a. Next line find years; if there are two we will need three columns in output (titles +, 2x year), if there are three we will need four (titles +, 3x year).. etc
b. Create title column + column for each year.
When reaching end of line, go to next line
a. Read text -> output to column 1.
b. Recognize spaces (Are spaces > 3?) as start of column 2. Read numbers -> output to column 2.
c. (if column = 3) Recognize spaces as start of column 3. Read numbers -> output to column 3.
d. (if column = 4) Recognize spaces as start of column 4. Read numbers -> output to column 4.
Each line, loop 4.
Next line does not include any numbers - End table. (probably the easiet just a user defined number, after 15 characters no number? end table)
I based my first version on Pdf to excel, but reading online people do not recommend OpenFile but rather FileSystemObject (even though it seems to be a lot slower).
Any pointers to get me started, mainly on step 2?
You have a number of ways to dissect a text file and depending on how complex it is might cause you to lean one way or another. I started this and it got a bit out of hand... enjoy.
Based on the sample you've provided and the additional comments, I noted the following. Some of these may work well for simple files but can get unwieldy with bigger more complex files. Furthermore, there may be slightly more efficient methods or tricks to what I have used here but this will definitely get you going an achieve the desired outcome. Hopefully this makes sense in conjunction with the code provided:
You can use booleans to help you determine what 'section' of the text file you are in. Ie use InStr on the current line to
determine you are in a Table by looking for the text 'Table' and then
once you know you are in the 'Table' section of the file start
looking for the 'Assets' section etc
You can use a few methods to determine the number of years (or columns) you have. The Split function along with a loop will do
the job.
If your files always have constant formatting, even only in certain parts, you can take advantage of this. For example, if you know your
file line will always have a dollar sign in front of the them, then
you know this will define the column widths and you can use this on
subsequent lines of text.
The following code will extract the Assets details from the text file, you can mod it to extract other sections. It should handle multiple rows. Hopefully I've commented it sufficient. Have a look and I'll edit if needs to help out further.
Sub ReadInTextFile()
Dim fs As Scripting.FileSystemObject, fsFile As Scripting.TextStream
Dim sFileName As String, sLine As String, vYears As Variant
Dim iNoColumns As Integer, ii As Integer, iCount As Integer
Dim bIsTable As Boolean, bIsAssets As Boolean, bIsLiabilities As Boolean, bIsNetAssets As Boolean
Set fs = CreateObject("Scripting.FileSystemObject")
sFileName = "G:\Sample.txt"
Set fsFile = fs.OpenTextFile(sFileName, 1, False)
'Loop through the file as you've already done
Do While fsFile.AtEndOfStream <> True
'Determine flag positions in text file
sLine = fsFile.Readline
Debug.Print VBA.Len(sLine)
'Always skip empty lines (including single spaceS)
If VBA.Len(sLine) > 1 Then
'We've found a new table so we can reset the booleans
If VBA.InStr(1, sLine, "Table") > 0 Then
bIsTable = True
bIsAssets = False
bIsNetAssets = False
bIsLiabilities = False
iNoColumns = 0
End If
'Perhaps you want to also have some sort of way to designate that a table has finished. Like so
If VBA.Instr(1, sLine, "Some text that designates the end of the table") Then
bIsTable = False
End If
'If we're in the table section then we want to read in the data
If bIsTable Then
'Check for your different sections. You could make this constant if your text file allowed it.
If VBA.InStr(1, sLine, "Assets") > 0 And VBA.InStr(1, sLine, "Net") = 0 Then bIsAssets = True: bIsLiabilities = False: bIsNetAssets = False
If VBA.InStr(1, sLine, "Liabilities") > 0 Then bIsAssets = False: bIsLiabilities = True: bIsNetAssets = False
If VBA.InStr(1, sLine, "Net Assests") > 0 Then bIsAssets = True: bIsLiabilities = False: bIsNetAssets = True
'If we haven't triggered any of these booleans then we're at the column headings
If Not bIsAssets And Not bIsLiabilities And Not bIsNetAssets And VBA.InStr(1, sLine, "Table") = 0 Then
'Trim the current line to remove leading and trailing spaces then use the split function to determine the number of years
vYears = VBA.Split(VBA.Trim$(sLine), " ")
For ii = LBound(vYears) To UBound(vYears)
If VBA.Len(vYears(ii)) > 0 Then iNoColumns = iNoColumns + 1
Next ii
'Now we can redefine some variables to hold the information (you'll want to redim after you've collected the info)
ReDim sAssets(1 To iNoColumns + 1, 1 To 100) As String
ReDim iColumns(1 To iNoColumns) As Integer
Else
If bIsAssets Then
'Skip the heading line
If Not VBA.Trim$(sLine) = "Assets" Then
'Increment the counter
iCount = iCount + 1
'If iCount reaches it's limit you'll have to redim preseve you sAssets array (I'll leave this to you)
If iCount > 99 Then
'You'll find other posts on stackoverflow to do this
End If
'This will happen on the first row, it'll happen everytime you
'hit a $ sign but you could code to only do so the first time
If VBA.InStr(1, sLine, "$") > 0 Then
iColumns(1) = VBA.InStr(1, sLine, "$")
For ii = 2 To iNoColumns
'We need to start at the next character across
iColumns(ii) = VBA.InStr(iColumns(ii - 1) + 1, sLine, "$")
Next ii
End If
'The first part (the name) is simply up to the $ sign (trimmed of spaces)
sAssets(1, iCount) = VBA.Trim$(VBA.Mid$(sLine, 1, iColumns(1) - 1))
For ii = 2 To iNoColumns
'Then we can loop around for the rest
sAssets(ii, iCount) = VBA.Trim$(VBA.Mid$(sLine, iColumns(ii) + 1, iColumns(ii) - iColumns(ii - 1)))
Next ii
'Now do the last column
If VBA.Len(sLine) > iColumns(iNoColumns) Then
sAssets(iNoColumns + 1, iCount) = VBA.Trim$(VBA.Right$(sLine, VBA.Len(sLine) - iColumns(iNoColumns)))
End If
Else
'Reset the counter
iCount = 0
End If
End If
End If
End If
End If
Loop
'Clean up
fsFile.Close
Set fsFile = Nothing
Set fs = Nothing
End Sub
I cannot examine the sample data as the PasteBin has been removed. Based on what I can glean from the problem description, it seems to me that using Regular Expressions would make parsing the data much easier.
Add a reference to the Scripting Runtime scrrun.dll for the FileSystemObject.
Add a reference to the Microsoft VBScript Regular Expressions 5.5. library for the RegExp object.
Instantiate a RegEx object with
Dim objRE As New RegExp
Set the Pattern property to "(\bd{4}\b){1,3}"
The above pattern should match on lines containing strings like:
2010
2010 2011
2010 2011 2012
The number of spaces between the year strings is irrelevant, as long as there is at least one (since we're not expecting to encounter strings like 201020112012 for example)
Set the Global property to True
The captured groups will be found in the individual Match objects from the MatchCollection returned by the Execute method of the RegEx object objRE. So declare the appropriate objects:
Dim objMatches as MatchCollection
Dim objMatch as Match
Dim intMatchCount 'tells you how many year strings were found, if any
Assuming you've set up a FileSystemObject object and are scanning the text file, reading each line into a variable strLine
First test to see if the current line contains the pattern sought:
If objRE.Test(strLine) Then
'do something
Else
'skip over this line
End If
Set objMatches = objRe.Execute(strLine)
intMatchCount = objMatches.Count
For i = 0 To intMatchCount - 1
'processing code such as writing the years as column headings in Excel
Set objMatch = objMatches(i)
e.g. ActiveCell.Value = objMatch.Value
'subsequent lines beneath the line containing the year strings should
'have the amounts, which may be captured in a similar fashion using an
'additional RegExp object and a Pattern such as "(\b\d+\b){1,3}" for
'whole numbers or "(\b\d+\.\d+\b){1,3}" for floats. For currency, you
'can use "(\b\$\d+\.\d{2}\b){1,3}"
Next i
This is just a rough outline of how I would approach this challenge. I hope there is something in this code outline that will be of help to you.
Another way to do this I have some success with is to use VBA to convert to a .doc or .docx file and then search for and pull tables from the Word file. They can be easily extracted into Excel sheets. The conversion seems to handle tables nicely. Note however that it works on a page by page basis so tables extending over a page end up as separate tables in the word doc.

Resources