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

Re: Automatically display UserForm when Word Document Opens by JGM

JGM
Fri Dec 05 21:08:05 CST 2003

Hi Pamela,

Change

> Private Sub ThisDocument_Document_Open()

to

Private Sub Document_Open()

and make sure that the Document_Open procedure is in the ThisDocument
module.

HTH
Cheers!

--
_______________________________________
Jean-Guy Marcil
jmarcil@sympatico.ca

"Pamela Cheek" <anonymous@discussions.microsoft.com> a écrit dans le message
de news: def001c3bb77$e59deb20$a601280a@phx.gbl...
> 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
>
>



Re: Automatically display UserForm when Word Document Opens by anonymous

anonymous
Thu Dec 11 14:07:45 CST 2003

Thanks it works like a charm
>-----Original Message-----
>Hi Pamela,
>
>Change
>
>> Private Sub ThisDocument_Document_Open()
>
>to
>
>Private Sub Document_Open()
>
>and make sure that the Document_Open procedure is in the=20
ThisDocument
>module.
>
>HTH
>Cheers!
>
>--
>_______________________________________
>Jean-Guy Marcil
>jmarcil@sympatico.ca
>
>"Pamela Cheek" <anonymous@discussions.microsoft.com> a=20
=E9crit dans le message
>de news: def001c3bb77$e59deb20$a601280a@phx.gbl...
>> I have a UserForm which has pulls information from a=20
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=20
word
>> document it is built upon. I don't want the tables to=20
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 =3D "Please wait while program shuts down" '=20
define
>> message
>> Style =3D vbYesOk + vbCritical + vbDefaultButton2 '
>> define message response buttons
>> Response =3D MsgBox(Msg, Style) ' Display message
>>
>> If True Then Unload UserForm1
>> Application.DisplayAlerts =3D False
>>
>> Word.Application.Quit
>>
>> End Sub
>>
>> Private Sub UserForm_Initialize()
>>
>>
>> Dim MyArray() As String
>> RowCount =3D ActiveDocument.Tables(1).Rows.Count
>> RowCount =3D ActiveDocument.Tables(1).Rows.Count
>> ColCount =3D ActiveDocument.Tables
(1).Columns.Count
>> ReDim MyArray(RowCount - 1, ColCount - 1)
>> For i =3D 1 To RowCount
>> For j =3D 1 To ColCount
>> 'Select each cell in the table
>> Celldata =3D ActiveDocument.Tables(1).Cell(i,=20
j)
>> 'Remove the paragraph and end-of-cell markers
>> 'as we lod the array
>>
>> MyArray(i - 1, j - 1) =3D Left(Celldata, Len
>> (Celldata) - 2)
>> Next
>> Next
>> ListBox1.ColumnCount =3D ColCount
>> ListBox1.List() =3D MyArray
>>
>>
>> Dim MyArrayExternal() As String
>> RowCount =3D ActiveDocument.Tables(2).Rows.Count
>> RowCount =3D ActiveDocument.Tables(2).Rows.Count
>> ColCount =3D ActiveDocument.Tables
(2).Columns.Count
>> ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
>> For m =3D 1 To RowCount
>> For n =3D 1 To ColCount
>> 'Select each cell in the table
>> Celldata =3D ActiveDocument.Tables(2).Cell(m,=20
n)
>> 'Remove the paragraph and end-of-cell markers
>> 'as we load the array
>> MyArrayExternal(m - 1, n - 1) =3D Left(Celldata,
>> Len(Celldata) - 2)
>> Next
>> Next
>> ListBox2.ColumnCount =3D ColCount
>> ListBox2.List() =3D MyArrayExternal
>>
>>
>> End Sub
>>
>> Private Sub ListBox1_Click()
>>
>> For x =3D 0 To ListBox1.ListCount
>>
>> If ListBox1.Selected(x) =3D 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 =3D 0 To ListBox2.ListCount
>>
>> If ListBox2.Selected(x) =3D 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,=20
but
>> will be at end product.
>>
>> How do I automatically Display a UserForm when the Word
>> Document is Opened?
>>
>> Any ideas?
>>
>> Thanks
>>
>> PAM
>>
>>
>
>
>.
>