Using an MS Word document, I'm utilising a UserForm for staff to complete an assessment. This document will be completed by numerous users (200+) at various times.
I have the form and document working well however I'm trying to manipulate hiding the document but keeping the UserForm shown to reduce clutter and avoid the document masking other applications when the UserForm is in focus.
When the staff member opens the Word Document, the UserForm auto opens:
Private Sub Document_Open()
Dim myForm As frmAssessment1
Set myForm = frmAssessment1
myForm.Show (0)
End Sub
When the UserForm opens:
Private Sub UserForm_Initialize()
'This defines tab 0 will display.
Me.MultiPage1.Value = 0
'This hides MS Word but remains open in the background.
Application.Visible = False
Dim question1 As String
'Populates the combobox for the Team Number selection_
' with an array (currently 1-30).
cmbTeamNum.List = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30)
'Assigns the text range of the defined bookmark ("x") to a variable
question1 = ActiveDocument.Bookmarks("question1").Range.Text
'Assigns each variable to the label caption field.
With Selection
lblQ1.Caption = question1
End With
End Sub
Application.Visible = False
is working for me apart from showing no presence of Word (or the UserForm) on the Task Bar which I am anticipating to be an issue as each user will have several other Applications open and it's likely some will 'lose' the UserForm.
I've tried using ActiveDocument.WindowState = wdWindowStateMinimize
though as word isn't hidden this causes the document to come into focus when the UserForm is active which may mask other Applications being used and cause a poor user experience.
Other than finding the WindowState
method, I haven't discovered any other methods to achieve what I'm after nor have I found a way to create a Task Bar button/icon for the UserForm (though there is plenty of info for Excel out there).
Am I correct in saying: There is no way to have only the UserForm show and still have a button/icon on the Task Bar -OR- there is no way to create an icon on the Task Bar for the UserForm?
If I'm not correct, how can I achieve this?
After some self education on Windows API functions I still know basically nothing, but I understand enough to be confident to test the excel solutions and it turns out that (at least the one I tested) it works!
I'm not the biggest fan of blindly accepting someone elses code without at least understanding the syntax/logic.
I specifically tested the code provided in Gareth's Answer which worked in both Word 2007 and Excel 2007 with minimal changes. I'm assuming this will work all the same in Office 2010 Applications which is what I'm using at work.
I adjusted the following section of the code:
Private Sub UserForm_Activate()
Application.Visible = False
'Application.VBE.MainWindow.Visible = False
AppTasklist Me
End Sub
Specifically I commented out Application.VBE.MainWindow.Visible = False
as with this line included in the code, it would not compile with the following rune-time error present:
Excel
Run-time error '1004':
Programmatic access to Visual Basic Project is not trusted
Word
Run-time error '6068':
Programmatic access to Visual Basic Project is not trusted
Chip Pearson posted a fantastic peice on Extending The Capabilities Of VBA UserForms With Windows API Functions which covers quite a few additional adjustments including showing the minimize and maximize buttons which included with the above referenced answer would make quite a useful adjustment to the UserForm.