P
Pamela Cheek
I have a UserForm which has pulls information from a Word
document that contains nothing but two tables of
information.
The UserForm works great, and exits gracefully, but will
not automatically display when the end user opens the word
document it is built upon. I don't want the tables to be
visible to the user, just the form. Code follows:
Private Sub ThisDocument_Document_Open()
Load UserForm1
UserForm1.Show vbModeless
End Sub
Private Sub CommandButton2_Click()
Dim Msg, Style 'set dim for message box when Exit is
pressed
Msg = "Please wait while program shuts down" ' define
message
Style = vbYesOk + vbCritical + vbDefaultButton2 '
define message response buttons
Response = MsgBox(Msg, Style) ' Display message
If True Then Unload UserForm1
Application.DisplayAlerts = False
Word.Application.Quit
End Sub
Private Sub UserForm_Initialize()
Dim MyArray() As String
RowCount = ActiveDocument.Tables(1).Rows.Count
RowCount = ActiveDocument.Tables(1).Rows.Count
ColCount = ActiveDocument.Tables(1).Columns.Count
ReDim MyArray(RowCount - 1, ColCount - 1)
For i = 1 To RowCount
For j = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(1).Cell(i, j)
'Remove the paragraph and end-of-cell markers
'as we lod the array
MyArray(i - 1, j - 1) = Left(Celldata, Len
(Celldata) - 2)
Next
Next
ListBox1.ColumnCount = ColCount
ListBox1.List() = MyArray
Dim MyArrayExternal() As String
RowCount = ActiveDocument.Tables(2).Rows.Count
RowCount = ActiveDocument.Tables(2).Rows.Count
ColCount = ActiveDocument.Tables(2).Columns.Count
ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
For m = 1 To RowCount
For n = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(2).Cell(m, n)
'Remove the paragraph and end-of-cell markers
'as we load the array
MyArrayExternal(m - 1, n - 1) = Left(Celldata,
Len(Celldata) - 2)
Next
Next
ListBox2.ColumnCount = ColCount
ListBox2.List() = MyArrayExternal
End Sub
Private Sub ListBox1_Click()
For x = 0 To ListBox1.ListCount
If ListBox1.Selected(x) = True Then
MsgBox ListBox1.List(x) & ListSeparator
& " " & " Office Symbol: " & ListSeparator
& " " & ListBox1.List(x, 1) & " Project: " &
ListBox1.List(x, 2)
End If
Next x
End Sub
Private Sub ListBox2_Click()
For x = 0 To ListBox2.ListCount
If ListBox2.Selected(x) = True Then
MsgBox ListBox2.List(x) & ListSeparator
& " " & " Office Symbol: " & ListSeparator
& " " & ListBox2.List(x, 1) & " Project: " &
ListBox2.List(x, 2)
End If
Next x
End Sub
Obviously code is rough and not fully documented yet, but
will be at end product.
How do I automatically Display a UserForm when the Word
Document is Opened?
Any ideas?
Thanks
PAM
document that contains nothing but two tables of
information.
The UserForm works great, and exits gracefully, but will
not automatically display when the end user opens the word
document it is built upon. I don't want the tables to be
visible to the user, just the form. Code follows:
Private Sub ThisDocument_Document_Open()
Load UserForm1
UserForm1.Show vbModeless
End Sub
Private Sub CommandButton2_Click()
Dim Msg, Style 'set dim for message box when Exit is
pressed
Msg = "Please wait while program shuts down" ' define
message
Style = vbYesOk + vbCritical + vbDefaultButton2 '
define message response buttons
Response = MsgBox(Msg, Style) ' Display message
If True Then Unload UserForm1
Application.DisplayAlerts = False
Word.Application.Quit
End Sub
Private Sub UserForm_Initialize()
Dim MyArray() As String
RowCount = ActiveDocument.Tables(1).Rows.Count
RowCount = ActiveDocument.Tables(1).Rows.Count
ColCount = ActiveDocument.Tables(1).Columns.Count
ReDim MyArray(RowCount - 1, ColCount - 1)
For i = 1 To RowCount
For j = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(1).Cell(i, j)
'Remove the paragraph and end-of-cell markers
'as we lod the array
MyArray(i - 1, j - 1) = Left(Celldata, Len
(Celldata) - 2)
Next
Next
ListBox1.ColumnCount = ColCount
ListBox1.List() = MyArray
Dim MyArrayExternal() As String
RowCount = ActiveDocument.Tables(2).Rows.Count
RowCount = ActiveDocument.Tables(2).Rows.Count
ColCount = ActiveDocument.Tables(2).Columns.Count
ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
For m = 1 To RowCount
For n = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(2).Cell(m, n)
'Remove the paragraph and end-of-cell markers
'as we load the array
MyArrayExternal(m - 1, n - 1) = Left(Celldata,
Len(Celldata) - 2)
Next
Next
ListBox2.ColumnCount = ColCount
ListBox2.List() = MyArrayExternal
End Sub
Private Sub ListBox1_Click()
For x = 0 To ListBox1.ListCount
If ListBox1.Selected(x) = True Then
MsgBox ListBox1.List(x) & ListSeparator
& " " & " Office Symbol: " & ListSeparator
& " " & ListBox1.List(x, 1) & " Project: " &
ListBox1.List(x, 2)
End If
Next x
End Sub
Private Sub ListBox2_Click()
For x = 0 To ListBox2.ListCount
If ListBox2.Selected(x) = True Then
MsgBox ListBox2.List(x) & ListSeparator
& " " & " Office Symbol: " & ListSeparator
& " " & ListBox2.List(x, 1) & " Project: " &
ListBox2.List(x, 2)
End If
Next x
End Sub
Obviously code is rough and not fully documented yet, but
will be at end product.
How do I automatically Display a UserForm when the Word
Document is Opened?
Any ideas?
Thanks
PAM