VBA and MS Word

S

Stacy

Hello all... I have a quick question. I am using a in Word that the
user will place a check mark by the "sections" they want to pull up.
Then I use simple vba to pull these sections, combine them, and creat
a document. however, my code is not very clean, and I always end up
with a blank page at the beginning of the document. Anyone know of an
easy way to do this? my basic code is as follows...

If CheckBox11 = True Then
ActiveDocument.ActiveWindow.View.Type = wdMasterView
ActiveDocument.Subdocuments.AddFromFile _
Name:="F:\ITS\TestArea\Page 6"
End If
If CheckBox12 = True Then
ActiveDocument.ActiveWindow.View.Type = wdMasterView
ActiveDocument.Subdocuments.AddFromFile _
Name:="F:\ITS\TestArea\Page 7"

Also, I have no way of returning "back" to form... in case, let's say,
the user forgot to check a box. any ideas?

thanks in advance to anyone who helps.
 
H

Helmut Weber

Hi Stacy,
can't help you with the extra blank page,
as I can't set up an extra master document to test it.
I may be able to help you with an array of option buttons,
though it may be a bit demanding for beginners.
Forgive me, for saying so.
---
Dim ArrOpt() As OptionButton ' Array of Optionbuttons
Dim iOpt As Integer ' Number of option buttons

Private Sub CmdResult_Click()
Dim sFln As String ' Filename
Dim iCnt As Integer ' a counter
Dim bChk As Boolean ' boolean checked
sFln = "F:\ITS\TestArea\Page "
bChk = False
For iCnt = 1 To iOpt
If ArrOpt(iCnt).Value = True Then
bChk = True
MsgBox "True for Button " & Format(iCnt, "00")
With ActiveDocument
' untested section
' .ActiveWindow.View.Type = wdMasterView
' .Subdocuments.AddFromFile Name:=sFln & CStr(iCnt)
End With
Exit For
End If
Next
If Not bChk Then MsgBox "No Button is true"
End With
End Sub

Private Sub UserForm_Initialize()
' Count Optionbuttons
Dim oCnt As Control
Dim iCnt As Integer
For Each oCnt In Me.Controls
If TypeOf oCnt Is MSForms.OptionButton Then
iOpt = iOpt + 1
End If
Next
' create array of optionbuttons
ReDim ArrOpt(iOpt) As OptionButton
' assign each optionbutton
For Each oCnt In Me.Controls
If TypeOf oCnt Is MSForms.OptionButton Then
iCnt = iCnt + 1
Set ArrOpt(iCnt) = oCnt
' setting caption for testing
ArrOpt(iCnt).Caption = Format(iCnt, "Opt- 00")
End If
Next
End Sub
Note, that the "for each loop" over all controls,
seemably, processes them in the order they were created.
So I would recommend to delete all optionbuttons,
create a new one and add as many as you need
by coying and pasting. The code in the userform
should work with any number of optionbuttons.
 
Top