I am working on the same program as a previous question, but now I am having trouble aligning the output of my now-fixed program. I know some of it might look messed up, but somehow I got it to work.
Whatever the case, the output is unaligned with my headings and doesn't look good. I cannot figure out how to fix this.
Imports System.IO
Imports System.Convert
Public Class frmAll
'Declare Streamreader
Private objReader As StreamReader
'Declare arrays to hold the information
Private strNumber(24) As String
Private strName(24) As String
Private strSize(24) As String
Private decCost(24) As Integer
Private Sub frmAll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set objReader
objReader = New StreamReader("products.csv")
Call FillArray()
End Sub
Private Sub FillArray()
'Declare variables and arrays
Dim decCost(24, 1) As Decimal
Dim strFields() As String
Dim strRec As String
Dim intCount As Integer = 0
Dim chrdelim As Char = ToChar(",")
'Set strRec to read the lines
strRec = objReader.ReadLine
'Do while loop to fill array.
Do While strRec <> Nothing
strFields = strRec.Split(chrdelim)
strNumber(intCount) = strFields(0)
strName(intCount) = strFields(1)
strSize(intCount) = strFields(2)
decCost(intCount, 0) = ToDecimal(strFields(3))
decCost(intCount, 1) = ToDecimal(strFields(4))
'Set strRec to read the lines again
strRec = objReader.ReadLine
'increment the index
intCount += 1
Loop
Call Calculate(decCost)
End Sub
Private Sub Calculate(ByVal numIn(,) As Decimal)
'Define arrays to hold total cost
Dim decRowTotal(24) As Decimal
'Define variables to hold the counters for rows and columns
Dim intR As Integer
Dim intC As Integer
'Calcualte total cost
For intC = 0 To 1
For intR = 0 To 24
decRowTotal(intR) += numIn(intR, intC) * 1
Next
Next
Call Output(numIn, decRowTotal)
End Sub
Private Sub Output(ByVal NumIn(,) As Decimal, ByVal RowTotalIn() As Decimal)
Dim strOut As String
Dim intR As Integer = 0
Dim intC As Integer = 0
strOut = "ID" & vbTab & "Item" & vbTab & vbTab & vbTab & "Size" & vbTab & vbTab & vbTab & vbTab & "Total Price" &
vbCrLf & "--------------------------------------------------------------------------------------------------------------------------------------------------" &
vbCrLf
For intC = 0 To 24
strOut &= strNumber(intC) & vbTab
strOut &= strName(intC) & vbTab
strOut &= strSize(intC) & vbTab & vbTab
strOut &= RowTotalIn(intC).ToString("c")
strOut &= vbCrLf
Next
rtbAll.Text = strOut
End Sub
End Class
You are using the wrong tool for this kind of work.
You need a DataGridView instead of a RichTextBox.
With a DataGridView you can adjust the column size at your will.
The approach of using tabs to create pseudocolumns inside the richtextbox fails because, if some text (the item column for example) is longer than the space used to represent a tab, then the next tab will shift to a rightmost position and throughout the rest of the line the text is misaligned.
You can try to minimize the problem adding or removing tabs, but, unless the text pixel length equals the length reserved for your tabs, your columns will be misaligned.
In the link provided below you will find an example of a simple unbound datagridview filled with string data.
http://msdn.microsoft.com/en-us/library/5s3ce6k8(v=vs.100).aspx
Related
I classify myself as a beginner in programing. I have a userform that first looks up a number presented by the user. Example 12345, 12346,12347. The number entered into the textbox is searched for and then added to the listbox as a valid number. After the user enters all the numbers needed, they should be able to click change and update the records accordingly.
Private Sub Change_Click()
Dim i As Long
For i = LBound(RunArray) To UBound(RunArray)
' Code to update each record, still working on it.
Next
End Sub
Private Sub RunNumber_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim RunArray() As String
Dim RunCount As Integer
RunCount = 0
If KeyCode = 13 Then
With Sheets("Sheet1").Range("A:A")
Set RunFind = .Find(What:=RunNumber, _
After:=.Cells(.Cells.count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not RunFind Is Nothing Then
ReDim Preserve RunArray(RunCount)
RunArray(RunCount) = RunNumber.Value
RunNumberList.AddItem RunNumber.Value
RunNumber.Value = ""
RunCount = RunCount + 1
Else
MsgBox "The Run Number you entered was not found, Please the number and try again."
RunNumber.Value = ""
End If
End With
End If
End Sub
Private Sub CreateArrayFromListbox()
Dim nIndex As Integer
Dim vArray() As Variant
' dimension the array first instead of using 'preserve' in the loop
ReDim vArray(ListBox1.ListCount - 1)
For nIndex = 0 To ListBox1.ListCount - 1
vArray(nIndex) = ListBox1.List(nIndex)
Next
End Sub
i have an example how to do it with a combobox, (it's the same with a listbox, just change the name accordingly.
Option Explicit
Private Sub UserForm_Initialize()
Dim i&
Dim Arr()
With Me.ComboBox1
For i = 1 To 1000
.AddItem "Item " & i
Next i
Arr = .List
.Clear
End With
For i = 0 To 999
Debug.Print Arr(i, 0)
Next i
Erase Arr
End Sub
this is just a sample code, in real coding, you won't clear the combobox this early, or erase the array.
The results are shown in the immediate window (alt-F11 , and Ctrl-g).
Note : the array is 2 dimendionned, and 0 based (Option base 1, after Option Explicitcan make the whole module 1-based (arrays start at 1) ).
I think i've got a good start, but I'm having a tough time taking this to the finish line. Could someone help me out?
I have a name column(G) in my spreadsheet. I want to pull the only the last name out of each cell and assign it to an array called name_array.
I know that my If function is working because if I set each name_cell to the LastName variable it substitutes only the lastname in each cell of the column, but I cannot figure out how to assign that to the array.
Here is my code thus far. Can someone please help me out and point out what I'm missing?
Sub create_namear()
Dim name_array() As Variant
Dim name_range As Range
Dim name_cell As Range
Dim n As Long
Set name_range = ActiveSheet.Range("G2:G" & Range("G" & Rows.Count).End(xlUp).Row)
ReDim name_array(name_range.Cells.Count)
For Each name_cell In name_range.Cells
Dim Lastname As String
If InStr(name_cell, " ") > 0 Then
Lastname = Split(name_cell, " ")(1)
End If
name_array(n) = lastname.value
n = n + 1
Next name_cell
Debug.Print name_array(1)
End Sub
Name Column
Here is another way to achieve what you want without looping. I have commented the code so you should not have a problem understanding it.
BASIC LOGIC
To get the part after SPACE, you can use the formula =IFERROR(MID(G2,SEARCH(" ",G2,1),LEN(G2)-SEARCH(" ",G2,1)+1),"")
Now applying the formula in the entire range and getting the value using INDEX(FORMULA). You can find the explanation of this method in Convert an entire range to uppercase without looping through all the cells
CODE
Option Explicit
Sub Sample()
Dim ws As Worksheet
Dim rng As Range
Dim lRow As Long, i As Long
Dim FinalAr As Variant
'~~> Set this to the relevant sheet
Set ws = Sheet1
With ws
'~~> Find last row in col G
lRow = .Range("G" & .Rows.Count).End(xlUp).Row
'~~> Set your range
Set rng = .Range("G2:G" & lRow)
'~~> Get all the last names from the range and store them
'~~> in an array in 1 go!
FinalAr = Evaluate("index(IFERROR(MID(" & _
rng.Address & _
",SEARCH("" ""," & _
rng.Address & _
",1),LEN(" & _
rng.Address & _
")-SEARCH("" ""," & _
rng.Address & _
",1)+1),""""),)")
End With
'~~> Check the output
For i = LBound(FinalAr) To UBound(FinalAr)
Debug.Print ">"; FinalAr(i, 1)
Next i
End Sub
IN ACTION
ALTERNATIVE METHODS
Use Text To columns and then store the output in an array
Use Flash Fill to get the last names and then store the output in an array. One drawback of this method is that the names which do not have last name, it will show first name instead of a blank.
Sub create_namear()
Dim name_array() As Variant
Dim name_range As Range
Dim name_cell As Range
Dim n As Long
Set name_range = ActiveSheet.Range("G2:G" & Range("G" & Rows.Count).End(xlUp).Row)
ReDim name_array(0 to name_range.Cells.Count-1) '### 0-based array...
For Each name_cell In name_range.Cells
If InStr(name_cell, " ") > 0 Then
name_array(n) = Split(name_cell, " ")(1) 'simplify...
End If
n = n + 1
Next name_cell
Debug.Print name_array(1)
End Sub
Solution using Filter() (values with missing lastnames are excluded):
Sub ExtractLastNames()
Dim arr, name_array, i
arr = WorksheetFunction.Transpose(Range("G2:G" & Cells(Rows.Count, "G").End(xlUp).Row)) 'first, get the horizontal one-dimentional array from cells
name_array = Filter(arr, " ", True) 'second, filter out one-word and empty elements
For i = LBound(name_array) To UBound(name_array)
name_array(i) = Split(name_array(i))(1) 'third, replace name_array values with extracted lastnames
Next
Range("H2").Resize(UBound(name_array) + 1) = WorksheetFunction.Transpose(name_array) ' output
End Sub
Last Names to Array
The following will consider the substring after the last occurring space as the last name.
Option Explicit
Sub create_namear()
Dim ws As Worksheet: Set ws = ActiveSheet
Dim nRange As Range
Set nRange = ws.Range("G2:G" & ws.Range("G" & ws.Rows.Count).End(xlUp).Row)
Dim rCount As Long: rCount = nRange.Rows.Count
Dim nArray() As String: ReDim nArray(0 To rCount - 1)
Dim nCell As Range
Dim n As Long
Dim nmLen As Long
Dim LastSpacePosition As Long
Dim nmString As String
Dim LastName As String
For Each nCell In nRange.Cells
nmString = CStr(nCell.Value)
If InStr(1, nmString, " ") > 0 Then
LastSpacePosition = InStrRev(nCell.Value, " ")
nmLen = Len(nmString)
If LastSpacePosition < nmLen Then
LastName = Right(nmString, nmLen - LastSpacePosition)
nArray(n) = LastName
n = n + 1
End If
End If
Next nCell
If n = 0 Then Exit Sub
If n < rCount Then
ReDim Preserve nArray(0 To n - 1)
End If
Debug.Print "[" & LBound(nArray) & "," & UBound(nArray) & "]" _
& vbLf & Join(nArray, vbLf)
End Sub
Extension on Siddharth' s formula evaluation
These additions to Siddharth's valid code can be helpful, if there are less than 2 data rows in order to avoid
an unwanted evaluation of the title row 1:1 (in case of no data at all, see section 1.b) - This can be prevented by correcting a resulting row number lRow of only 1 to the actual data row start of 2.
Error 9 Subscript out of range (in case of a single element; see section 3.b) - Note that this requires to transform a 1-dim result to a 2-dim results array by means of a adequately dimensioned tmp array.
Furthermore I simplified the formula building to avoid repeated rng.Address insertions just to show another way of doing it (see section 2.).
Sub GetLastName()
'0. Set this to the relevant sheet
Dim ws As Worksheet: Set ws = Sheet1
With ws
'1. Define data range
'1. a) Find last row in col G
Dim lRow As Long
lRow = .Range("G" & .Rows.count).End(xlUp).Row
'1. b) Provide for empty data set ' << Added to avoid title row evaluation
If lRow = 1 Then lRow = 2
'1. c) Set your range
Dim rng As Range: Set rng = .Range("G2:G" & lRow)
'2. Define formula string parts ' << Modified for better readibility
Dim FormulaParts()
FormulaParts = Array("INDEX(IFERROR(MID(", _
",SEARCH("" "",", _
",1),LEN(", _
")-SEARCH("" "",", _
",1)+1),""""),)")
'3. Assign last names to 2-dim array results
'3. a) Get all the last names from the range and store them
Dim results
results = Evaluate(Join(FormulaParts, rng.Address))
End With
'3.b) Provide for single results '<< Added to avoid Error 9 Subscript o/Rng
If UBound(results) = 1 Then '<< Force single element into 2-dim array
Dim tmp(1 To 1, 1 To 1)
tmp(1, 1) = results(1)
results = tmp
End If
'h) Display in VB Editor's immediate window
Dim i As Long
For i = LBound(results) To UBound(results)
Debug.Print ">"; results(i, 1)
Next i
'i) Write last names to target '<< Added to demonstrate writing back
ws.Range("H2").Resize(UBound(results), 1) = results
End Sub
I am a VBA novice and I am trying to print an array that I was able to make (basically copying from another post) in VBA today. I placed a break into the script and inspected the array in the locals page to see that the array captures what I want (and some extra data that I will filter out). I spent the day reading about printing arrays on stack overflow and other sites and I ended up a bit lost. My goal is to export the array as a table in excel.
The script looks for underlined sentences in a 400 page word document and places them into the array. All that's really necessary for printing is the underlined sentences, so maybe an array wasn't the best approach? How can I export the array 'myWords' to a fresh excel document or one that I designate?
Many thanks for your help!
Sub addUnderlinedWordsToArray()
On Error GoTo errhand:
Dim myWords() As String
Dim i As Long
Dim myDoc As Document: Set myDoc = ActiveDocument ' Change as needed
Dim aRange As Range: Set aRange = myDoc.Content
Dim sRanges As StoryRanges: Set sRanges = myDoc.StoryRanges
Dim ArrayCounter As Long: ArrayCounter = 0 ' counter for items added to the array
Dim Sentence As Range
Dim w As Variant
Application.ScreenUpdating = False
ReDim myWords(aRange.Words.Count) ' set a array as large as the
' number of words in the doc
For Each Sentence In ActiveDocument.StoryRanges
For Each w In ActiveDocument.Sentences
If w.Font.Underline <> wdUnderlineNone Then
myWords(ArrayCounter) = w
ArrayCounter = ArrayCounter + 1
End If
Next
Next
Set myDoc = Nothing
Set aRange = Nothing
Set sRange = Nothing
Application.ScreenUpdating = True
Exit Sub
errhand:
Application.ScreenUpdating = True
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Subroutine Name: addUnderlinedWordsToArray" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
End Sub
I prefer to use Late Binding over adding an external reference to Excel. This will allow the code to work properly no mater what version of Office is installed.
Sub addUnderlinedWordsToArray()
On Error GoTo errhand:
Dim myWords() As String
Dim i As Long
Dim myDoc As Document: Set myDoc = ActiveDocument ' Change as needed
Dim aRange As Range: Set aRange = myDoc.Content
Dim sRanges As StoryRanges: Set sRanges = myDoc.StoryRanges
Dim ArrayCounter As Long: ArrayCounter = 0 ' counter for items added to the array
Dim Sentence As Range
Dim w As Variant
Application.ScreenUpdating = False
ReDim myWords(aRange.Words.Count) ' set a array as large as the
' number of words in the doc
For Each Sentence In ActiveDocument.StoryRanges
For Each w In ActiveDocument.Sentences
If w.Font.Underline <> wdUnderlineNone Then
myWords(ArrayCounter) = w
ArrayCounter = ArrayCounter + 1
End If
Next
Next
ReDim Preserve myWords(ArrayCounter - 1)
AddWordsToExcel myWords
Set myDoc = Nothing
Set aRange = Nothing
Set sRange = Nothing
Application.ScreenUpdating = True
Exit Sub
errhand:
Application.ScreenUpdating = True
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Subroutine Name: addUnderlinedWordsToArray" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
End Sub
Sub AddWordsToExcel(myWords() As String)
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
Dim wb As Object
Set wb = xlApp.Workbooks.Add
wb.Worksheets(1).Range("A1").Resize(UBound(myWords) + 1).Value = xlApp.Transpose(myWords)
xlApp.Visible = True
End Sub
This is tested and working fine :
Option Explicit
Sub addUnderlinedWordsToArray()
Dim myWords() As String
Dim i As Long
Dim myDoc As Document: Set myDoc = ActiveDocument ' Change as needed
Dim aRange As Range: Set aRange = myDoc.Content
Dim sRanges As StoryRanges: Set sRanges = myDoc.StoryRanges
Dim ArrayCounter As Long: ArrayCounter = 0 ' counter for items added to the array
Dim Sentence As Range
Dim w As Variant
Dim Ex0 As Excel.Application
Dim Wb0 As Workbook
Application.ScreenUpdating = False
On Error GoTo errhand:
For Each Sentence In ActiveDocument.StoryRanges
For Each w In ActiveDocument.Sentences
If w.Font.Underline <> wdUnderlineNone Then
ReDim Preserve myWords(ArrayCounter)
myWords(ArrayCounter) = w
ArrayCounter = ArrayCounter + 1
End If
Next
Next
On Error GoTo 0
Set myDoc = Nothing
Set aRange = Nothing
Set sRanges = Nothing
Set Ex0 = New Excel.Application
Set Wb0 = Ex0.workbooks.Add
Ex0.Visible = True
Wb0.Sheets(1).Range("A1").Resize(UBound(myWords) + 1, 1) = WorksheetFunction.Transpose(myWords)
Application.ScreenUpdating = True
Debug.Print UBound(myWords())
Exit Sub
errhand:
Application.ScreenUpdating = True
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Subroutine Name: addUnderlinedWordsToArray" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
End Sub
Make sure to have the Microsoft Excel 14.0 Object Library ticked in Tools/References
The code provided in the question has some problems, which I've tried to correct as per the problem description.
The code declares a number of object variables, assigning them in the same line as the declaration, but these objects are never used. In order to improve code readability and make these objects "obvious" I've moved the instantiations to new lines.
The sample code below then substitutes these objects for the ActiveDocument... objects used in the original code, where these objects are intended to be used. This makes the code more readabile and more efficient.
The use of StoryRanges is questionable in the context of the code. StoryRanges are not the same as Sentences. On the assumption that the use of StoryRanges was a misunderstanding or typo, I've changed the code to use Sentences. If StoryRanges is meant, the code can loop through them, but certain structural changes would be required. (StoryRanges enables code to access all parts of a document such as TextBoxes, Headers, Footers, Endnotes - instead of just the main body of the document.)
It makes no sense to loop sentences while sizing the array to the number of words in the document. This has been changed to the number of sentences, which will require less memory.
Only the text, not the entire sentence Range should be added to the array since Excel can't do anything with a Word.Range except accept its text. This will require less memory.
On the assumption that not every sentence in the document is underlined, it's not necessary to maintain an array with empty members, so after the loop the array is resized to contain only those that have been populated. (ReDim Preserve myWords(ArrayCounter - 1)). This will avoid writing "empty" content to the Excel worksheet.
The code to write to Excel is in a separate procedure, making it re-usable for other arrays that might need to be transferred to Excel. The code has been written as late-binding, making it independent of requiring a reference to the Excel library. If early-binding (with a reference) is desired, those declarations are commented out in-line.
The writing to Excel only occurs if the array contains members. If ArrayCounter has never been incremented, the call to the other procedure is not performed.
The Excel objects are set to Nothing at the end of that procedure.
Note: The code posted in the question and used here picks up any sentence that contains an underline.
Sample code:
Sub addUnderlinedWordsToArray()
On Error GoTo errhand:
Dim myWords() As String
Dim i As Long
Dim myDoc As Document
Dim aRange As Range
Dim sRanges As Sentences
Dim ArrayCounter As Long ' counter for items added to the array
Dim Sentence As Range
Dim w As Variant
Application.ScreenUpdating = False
Set myDoc = ActiveDocument ' Change as needed
Set aRange = myDoc.content
Set sRanges = myDoc.Sentences
ArrayCounter = 0
ReDim myWords(aRange.Sentences.Count - 1) ' set a array as large as the
' number of sentences in the doc
For Each Sentence In sRanges
If Sentence.Font.Underline <> wdUnderlineNone Then
myWords(ArrayCounter) = Sentence.text
ArrayCounter = ArrayCounter + 1
End If
Next
If ArrayCounter > 0 Then
ReDim Preserve myWords(ArrayCounter - 1)
WriteToExcel myWords
End If
Set myDoc = Nothing
Set aRange = Nothing
Set sRanges = Nothing
Application.ScreenUpdating = True
Exit Sub
errhand:
Application.ScreenUpdating = True
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Subroutine Name: addUnderlinedWordsToArray" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
End Sub
Sub WriteToExcel(a As Variant)
Dim appExcel As Object 'Excel.Application
Dim wb As Object ' Excel.Workbook
Dim r As Object ' Excel.Range
Dim i As Long
Set appExcel = CreateObject("Excel.Application")
appExcel.Visible = True
appExcel.UserControl = True
Set wb = appExcel.Workbooks.Add
Set r = wb.Worksheets(1).Range("A1")
r.Resize(UBound(myWords) + 1).Value = xlApp.Transpose(myWords)
Set r = Nothing
Set wb = Nothing
Set appExcel = Nothing
End Sub
The general answer is to use Range ("A1") = myWords(ArrayCounter)
You would need to step through the array while simultaneously moving to the next cell.
You could also use Range ("A1:B3") = myWords.
I'm trying to use userforms in word VBA to save an undefined number of variables into an array to later input in a document but I can't get the incremental counter to work and it will only save the last input and it is saved as input 0.
Public i As Integer
Sub Macro6()
UF1.Show
End Sub
Private Sub btnAddC_Click()
Dim CName(100) As String
Dim CAddress(100) As String
CName(i) = txtName.Text
CAddress(i) = txtAddress.Text
i = i + 1
Unload Me
UF1.Show
End Sub
Private Sub btnNext_Click()
Dim CName(100) As String
Dim CAddress(100) As String
Dim n As Integer
CName(i) = txtName.Text
CAddress(i) = txtAddress.Text
Unload Me
For n = 0 To i
Selection.TypeText Text:="Client number " & n & " is " & CName(n) & "."
Selection.TypeParagraph
Selection.TypeText Text:="Client number " & n & " is " & CAddress(n) & "."
Selection.TypeParagraph
Next
End Sub
Private Sub UserForm_Initialize()
txtName.Text = ""
txtAddress.Text = ""
End Sub
The output is always:
Client number 0 is a.
Client number 0 is b.
I'm designing a slide checker to look for mismatched fonts and colours, and need to keep track of each colour for each shape in an array. My problem is that for some reason the array get's cleared. I've put in flags to check that the array is being properly assigned. As it moves through the loop, it correctly adds 1 to the array, updates the colour for that index, then moves forward. For some reason when it gets to the msgbox check, the array still has the correct number of indexes, but the array is empty for every shape except for the last shape in the loop. For example one shape has 5 lines, another shape has 2. I'll get a msgbox 7 times, but the first 5 are empty, and the next 2 have the actual colour.
Private Sub CommandButton1_Click()
Dim x As Integer
Dim i As Integer
Dim a As Integer
Dim b As Integer
Dim shpCount As Integer
Dim lFindColor As Long
Dim oSl As Slide
Dim oSh As Shape
Dim colorsUsed As String
Dim fontsUsed As String
Dim lRow As Long
Dim lCol As Long
Dim shpFont As String
Dim shpSize As String
Dim shpColour As String
Dim shpBlanks As Integer: shpBlanks = 0
Dim oshpColour()
Set oSl = ActiveWindow.View.Slide
For Each oSh In oSl.Shapes
'----Shape Check----------------------------------------------------------
With oSh
If .HasTextFrame Then
If .TextFrame.HasText Then
shpCount = shpCount + .TextFrame.TextRange.Runs.Count
ReDim oshpColour(1 To shpCount)
For x = 1 To .TextFrame.TextRange.Runs.Count
a = a + 1
oshpColour(a) = .TextFrame.TextRange.Runs(x).Font.Color.RGB
shpFont = shpFont & .TextFrame.TextRange.Runs(x).Font.Name & ", "
shpSize = shpSize & .TextFrame.TextRange.Runs(x).Font.Size & ", "
shpColour = shpColour & .TextFrame.TextRange.Runs(x).Font.Color.RGB & ", "
Next
End If
End If
Next
MsgBox "Shape Fonts: " & shpFont & vbCrLf & "Shape Font Sizes: " & shpSize & vbCrLf & "Shape Font Colours: " & shpColour
For b = LBound(oshpColour) To UBound(oshpColour)
MsgBox oshpColour(b)
Next
End Sub
The right way to redim an array keeping it content is as follows:
ReDim Preserve oshpColour(1 To shpCount)