VBA code for inserting unique text to each of 12 cells, when cells are blank - vba

I am new to VBA and am severely stuck! I have 12 cells that I need to add specific text to, but only if the cells are blank. I managed to find code for 1 of them which is shown below:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$D$3" Then
If Target.Value = "Insert name of project (if known)" Then
Target.Font.ColorIndex = xlAutomatic
Target.Value = ""
Exit Sub
End If
End If
If [D3].Value = "" Then
[D3].Value = "Insert name of project (if known)"
[D3].Font.ColorIndex = 1
Else
[D3].Font.ColorIndex = xlAutomatic
End If
End Sub
However, seemingly I can only use this once per sheet. I need code that is similar to this that will hopefully do the same job. The remaining 11 cells need to have unique text.
Basically what I am trying to do is prompt the user to insert details in each of these cells and once the cells are filled, the form will be complete.
Any assistance is appreciated.
Hi, Apologies for the delay. This is the final edit, which works perfectly. I thought I was going to have an issue with 'undo' (CTRL+Z) but it seems to be fine now. Thanks again.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim clls(1 To 12) As String
Dim msg(1 To 12) As String
Dim i As Long, addr As String, c As Range
clls(1) = "D3": msg(1) = "Insert name of project (if known)"
clls(2) = "D4": msg(2) = "Insert closest street address"
clls(3) = "H3": msg(3) = "Insert name of landowner (if applicable)"
clls(4) = "H4": msg(4) = "Insert name of Developer (if applicable)"
clls(5) = "H6": msg(5) = "Insert name of PM Co. (if different from above)"
clls(6) = "H7": msg(6) = "Insert name of Designer (if applicable)"
clls(7) = "H8": msg(7) = "Insert name of Constructor"
clls(8) = "L3": msg(8) = "Insert project number (if known)"
clls(9) = "L6": msg(9) = "Insert name"
clls(10) = "L7": msg(10) = "Insert submission date"
clls(11) = "D10": msg(11) = "Brief description of project: Adjustment, deviation, main upsizing, main extension, lead-in, lead-out, etc."
clls(12) = "D11": msg(12) = "Insert length of asset (number only)"
Set c = Target.Cells(1)
addr = c.Address(False, False)
For i = 1 To UBound(clls)
If addr = clls(i) Then
If c.Value = msg(i) Then
c.Font.ColorIndex = xlAutomatic
c.Value = ""
End If
Else
With Me.Range(clls(i))
If .Value = "" Then
.Value = msg(i)
.Font.ColorIndex = 1
End If
End With
End If
Next i
End Sub

Might need a bit of tweaking...
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim clls(1 To 5) As String
Dim msg(1 To 5) As String
Dim i As Long, addr As String, c As Range
clls(1) = "D3": msg(1) = "Message 1"
clls(2) = "D4": msg(2) = "Message 2"
clls(3) = "D5": msg(3) = "Message 3"
clls(4) = "D6": msg(4) = "Message 4"
clls(5) = "D7": msg(5) = "Message 5"
Set c = Target.cells(1)
addr = c.Address(False, False)
For i = 1 To UBound(clls)
If addr = clls(i) Then
If c.Value = msg(i) Then
c.Font.ColorIndex = xlAutomatic
c.Value = ""
End If
Else
With Me.Range(clls(i))
If .Value = "" Then
.Value = msg(i)
.Font.ColorIndex = 1
End If
End With
End If
Next i
End Sub

Related

Is it possible to edit the input in a UserForm in VBA?

I am creating a yard management system to keep track of open parking spots in a lot. The userform allows the user to click on a spot in the map that is open and fill out a list of information about the truck going to that spot. Right now, if I make an error in the entry I have to redo the whole form, rather than just being able to edit the information I have already entered. Is there a way to do that without having to retype everything?
Here is the code for the user form:
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdClear_Click()
ActiveCell.ClearContents
ActiveCell.Interior.Color = vbGreen
Unload Me
End Sub
Private Sub cmdUpdate_Click()
UpdateInfo.Show
Unload Me
End Sub
Private Sub CommandButton1_Click()
UpdateInfo.Show
Unload Me
End Sub
Private Sub UserForm_Initialize()
lblInfo = ActiveCell.Value
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set rngBDock = Range("BX7:CO7")
Set rngBulk = Range("BZ21:CG21")
Set rngTransT = Range("BF17:BY17")
Set rngTransT1 = Range("BG21:BY21")
Set rngTDock = Range("BL7:BW7")
Set rngEDock = Range("CP7:CT7")
Set rngNDock = Range("CU7:DC7")
Set rngFence = Range("CQ13:CV13")
Set rngNSide = Range("CW13:DB13")
Set rngGEO = Range("BG28:DD28")
Set rngNight = Range("CH21:DD21")
Set rngNewT = Range("DK31:DK65")
Set rngNewTl = Range("DI31:DI65")
Set rngOff = Range("BN40:CL40")
Set rngOffl = Range("BN42:CL42")
Set rng = Union(rngBDock, rngBulk, rngTransT, rngTransT1, rngTDock, rngEDock, rngNDock, rngFence, rngNSide, rngGEO, rngNight, rngNewT, rngNewTl, rngOff, rngOffl)
If Not Intersect(Target, rng) Is Nothing Then
CellInfo.Show
'ActiveCell.Value = cellFill
If Not IsEmpty(ActiveCell.Value) Then
Call RealTimeTracker
End If
End If
Private Sub cmdOkUpdate_Click()
Dim i As Integer, j As Integer
For i = 0 To lbxOption.ListCount - 1
If lbxOption.Selected(i) Then j = j + 1
Next i
If j = 0 Then
MsgBox "Please select an option. ", , "Warning"
Unload Me
UpdateInfo.Show
ElseIf j = 1 Then
NoFill = False
End If
strBOL = txtBOL.Value
strID = txtID.Value
details = txtDet.Value
opt = lbxOption.Value
currtime = time()
today = Format(Now(), "MM/DD/YYYY")
emp = TextBox1.Value
With ActiveCell
spot = .Offset(-1, 0)
If Len(spot) = 0 Then
spot = .Offset(1, 0)
Else
spot = spot
End If
End With
If NoFill = True Then
cellFill = ""
ElseIf NoFill = False Then
With Sheet5
.Range("A1").Value = "Time"
.Range("B1").Value = "Date"
.Range("C1").Value = "Location"
.Range("D1").Value = "Category"
.Range("E1").Value = "BOL"
.Range("f1").Value = "Trailer #"
.Range("g1").Value = "Details"
.Range("H1").Value = "EE Name"
.Range("A2").EntireRow.Insert
.Range("A2").Value = currtime
.Range("B2").Value = today
.Range("C2").Value = spot
.Range("D2").Value = opt
.Range("E2").Value = strBOL
.Range("F2").Value = strID
.Range("G2").Value = details
.Range("H2").Value = emp
.Columns("A:H").AutoFit
End With
If Not IsEmpty(opt) Then
cellFill = opt & " " & vbCrLf & "BOL (last 5 digits): " & strBOL & " " & vbCrLf & "Trailer # " & strID & " " & vbCrLf & details & "EE Name" & emp & " " & vbCrLf
ActiveCell.Value = cellFill
Call RealTimeTracker
End If
End If
Unload Me
Sheet1.Activate
End Sub

VBA Send Email When Cell Value Changes

Need to find a way to offset the cell value in the email body. For whichever cell value triggers the email (meaning our target has been reached) I want to return the corresponding row value 12 columns to the left. You'll see in my code I've used Target.Offset(0, -12) but this is returning an error. I hope that makes sense.
Private Sub Worksheet_Calculate()
Dim Target As Range
With Me
Set Target = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp))
End With
If (Range("N45") = Range("F45")) Or (Range("N46") = Range("F46")) Or (Range("N47") = Range("F47")) Or (Range("N48") = Range("F48")) Or (Range("N50") = Range("F50")) Or (Range("N51") = Range("F51")) Or (Range("N52") = Range("F53")) Or (Range("N55") = Range("F55")) Or (Range("N56") = Range("F56")) Or (Range("N57") = Range("F57")) Or (Range("N58") = Range("F58")) Or (Range("N59") = Range("F59")) Or (Range("N61") = Range("F61")) Or (Range("N62") = Range("F62")) Or (Range("N63") = Range("F63")) Or (Range("N65") = Range("F65")) Or (Range("N66") = Range("F66")) Or (Range("N67") = Range("F67")) Or (Range("N68") = Range("F68")) Or (Range("N70") = Range("F70")) Or (Range("N71") = Range("F71")) Or (Range("N73") = Range("F73")) Or (Range("N74") = Range("F74")) Or (Range("N75") = Range("F75")) Or (Range("N76") = Range("F76")) Or (Range("N77") = Range("F77")) Or (Range("N79") = Range("F79")) Or (Range("N80") = Range("F80")) Or (Range("N81") = Range("F81")) Or (Range("N83") = Range("F83")) And _
(Range("N84") = Range("F84")) Or (Range("N85") = Range("F85")) Or (Range("N87") = Range("F87")) Or (Range("N88") = Range("F88")) Or (Range("N89") = Range("F89")) Or (Range("N91") = Range("F91")) Or (Range("N92") = Range("F92")) Or (Range("N93") = Range("F93")) Or (Range("N95") = Range("F95")) Or (Range("N96") = Range("F96")) Or (Range("N97") = Range("F97")) Or (Range("N99") = Range("F99")) Or (Range("N100") = Range("F100")) Or (Range("N101") = Range("F101")) Or (Range("N103") = Range("F103")) Or (Range("N104") = Range("F104")) Or (Range("N105") = Range("F105")) Or (Range("N106") = Range("F106")) Or (Range("N108") = Range("F108")) Or (Range("N109") = Range("F109")) Or (Range("N110") = Range("F110")) Or (Range("N111") = Range("F111")) Or (Range("N113") = Range("F113")) Or (Range("N114") = Range("F114")) Or (Range("N115") = Range("F115")) Or (Range("N116") = Range("F116")) Or (Range("N117") = Range("F117")) Or (Range("N118") = Range("F118")) Or (Range("N121") = Range("F121")) And _
(Range("N122") = Range("F122")) Or (Range("N123") = Range("F123")) Or (Range("N124") = Range("F124")) Or (Range("N125") = Range("F125")) Or (Range("N127") = Range("F127")) Or (Range("N128") = Range("F128")) Or (Range("N132") = Range("F132")) Or (Range("F134") = Range("N134")) Or (Range("N136") = Range("F136")) Or (Range("N138") = Range("F138")) Or (Range("N140") = Range("F140")) Or (Range("N142") = Range("F142")) And _
(Range("N145") = Range("F145")) Or (Range("N146") = Range("F146")) Or (Range("N147") = Range("F147")) Or (Range("N148") = Range("F148")) Or (Range("N149") = Range("F149")) Or (Range("N150") = Range("F150")) Or (Range("N153") = Range("F153")) Or (Range("N154") = Range("F154")) Or (Range("N156") = Range("F156")) Or (Range("N157") = Range("F157")) Or (Range("N159") = Range("F159")) Or (Range("N160") = Range("F160")) Or (Range("N161") = Range("F161")) Or (Range("N162") = Range("F162")) Or (Range("N163") = Range("F163")) Or (Range("N164") = Range("F164")) Or (Range("N166") = Range("F166")) Or (Range("N167") = Range("F167")) Or (Range("N168") = Range("F168")) Or (Range("N169") = Range("F169")) Or (Range("N170") = Range("F170")) Or (Range("N171") = Range("F171")) Or (Range("N173") = Range("F173")) Or (Range("N174") = Range("F174")) Or (Range("N175") = Range("F175")) Or (Range("N176") = Range("F176")) Or (Range("N177") = Range("F177")) Or (Range("N178") = Range("F178")) And _
(Range("N180") = Range("F180")) Or (Range("N182") = Range("F182")) Or (Range("N184") = Range("F184")) Or (Range("N185") = Range("F185")) Or (Range("N186") = Range("F186")) Or (Range("N187") = Range("F187")) Or (Range("N188") = Range("F188")) Or (Range("N189") = Range("F189")) Or (Range("N191") = Range("F191")) Or (Range("N192") = Range("F192")) Or (Range("N193") = Range("F193")) Or (Range("N195") = Range("F195")) Or (Range("N196") = Range("F196")) Or (Range("N197") = Range("F197")) Or (Range("N198") = Range("F198")) Or (Range("N199") = Range("F199")) Or (Range("N200") = Range("F200")) Or (Range("N201") = Range("F201")) Or (Range("N202") = Range("F202")) Or (Range("N203") = Range("F203")) Or (Range("N205") = Range("F205")) Or (Range("N206") = Range("F206")) Or (Range("N207") = Range("F207")) Or (Range("N208") = Range("F208")) Or (Range("N209") = Range("F209")) Or (Range("N210") = Range("F210")) Or (Range("N211") = Range("F211")) Or (Range("N212") = Range("F212")) And _
(Range("N213") = Range("F213")) Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
Target.Offset(0, -12) & " has reached its target"
On Error Resume Next
With xOutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "Target Reached"
.Body = xMailBody
.Send 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Here I have used the Worksheet_Change event and the Offset works fine.
Dim xRg As Range
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Target, Range("D1:D99"))
If xRg Is Nothing Then Exit Sub
If (Range("D7") > Range("E7")) Or (Range("D8") > Range("E8")) Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
xRg.Offset(0, -3) & " has reached its target"
On Error Resume Next
With xOutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "Target Reached"
.Body = xMailBody
.Send 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Target.Offset(0, -12) in your Mail_small_Text_Outlook isn't defined. You can't set a variable in one subroutine and then use it in another unless that variable has been defined globally (outside of all subroutines and functions) or it is passed as a parameter to the subroutine.
Try instead:
Sub Mail_small_Text_Outlook(Target as Range)
Then calling that subroutine like:
Call Mail_small_Text_Outlook(Target)
With that you are passing the variable Target to the Mail_small_Text_Outlook subroutine.
Alternatively to set Target as a global variable so it is available to subroutines and functions in your VBAProject (I wouldn't in this case for reasons). You add to the top of your code (above your worksheet_calculate routine):
Public Target as Range
Then remove your declaration of Target in your worksheet_calculate routine:
'Dim Target As Range
Although, if you do this, then change the name of the variable since there are other built in subroutines like Worksheet_Change() that have Target as a built in variable and the scope is going to get all weird then.

Change label text with a button click in VBA

I'm new to VBA and I have the following code :
Private Sub CommandButton3_Click()
CommandButton2.Enabled = False
Dim x As Integer
For x = 1 To 14
Me.Controls("textbox" & x).Value = ""
Next x
Application.DoEvents
'Probleeeeeeeeem
Me.Label8.Text = ""
Me.Label9.Text = ""
Me.Label10.Text = ""
Me.Label11.Text = ""
Me.Label12.Text = ""
Me.Label13.Text = ""
End Sub
The labels text (from 8 to 13) have already some values generated by another piece of code. How can I change those values to a void string with a CommandButton3_Click() ?
I tried Application.DoEventsand Me.Refresh but In vain, here is the error message I get :
Error message
Thank you

Excel keeps crashing with Worksheet_selectionChange

I am running two VBA formulas.
The first hides all cells with empty information the first column.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
On Error Resume Next
Application.ScreenUpdating = False
For Each c In Range("A3:A49")
If c.Value = vbNullString Then
c.EntireRow.Hidden = True
End If
Next c
For Each c In Range("A3:A47")
If c.Value <> vbNullString Then
c.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = True
End Sub
The second Formula strings data together and placeses this information in the next cell that is empty (aka the first hidden cell) when the button is clicked.
Option Explicit
Dim iwsh As Worksheet
Dim owsh As Worksheet
Dim output As String
Dim i As Integer
Sub Copy()
Set iwsh = Worksheets("Budget")
Set owsh = Worksheets("Release Burnup")
i = 3
While owsh.Cells(i, 1) <> ""
i = i + 1
Wend
output = "R" & iwsh.Cells(13, 2).Value & "-S" & iwsh.Cells(14, 2).Value
owsh.Cells(i, 1) = output
ActiveSheet.EnableCalculation = False
ActiveSheet.EnableCalculation = True
End Sub
Previously, this has been causing no problem... Something has happened that is causing the workbook to crash anytime I try to delete information out of one of the cells with the new data.
PS: This is the list of my other formulas. maybe there is something in these that is interacting with the formentioned code?
Private Sub NewMemberBut_Click()
'causes userform to appear
NewMember.Show
'reformats button because button kept changing size and font
NewMemberBut.AutoSize = False
NewMemberBut.AutoSize = True
NewMemberBut.Height = 40.25
NewMemberBut.Left = 303.75
NewMemberBut.Width = 150
End Sub
'Similar code to the problematic code in question, but this one works fine
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
On Error Resume Next
Application.ScreenUpdating = False
For Each c In Range("A3:A35,A41:A80")
If c.Value = vbNullString Then
c.EntireRow.Hidden = True
End If
Next c
For Each c In Range("A3:A35,A41:A80")
If c.Value <> vbNullString Then
c.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = True
End Sub
'Code for UserForm
Option Explicit
Dim mName As String
Dim cName As String
Dim mRole As String
Dim cRole As String
Dim i As Integer
Dim x As Integer
Dim Perc As Integer
Dim Vac As Integer
Dim Prj As Worksheet
Dim Bud As Worksheet
Private Sub NewMember_Initialize()
txtName.Value = ""
cboRoleList.Clear
Scrum.Value = False
txtPercent.Value = ""
txtVacation.Value = ""
txtName.SetFocus
End Sub
Private Sub AddMember_Click()
If Me.txtName.Value = "" Then
MsgBox "Please enter a Member name.", vbExclamation, "New Member"
Me.txtName.SetFocus
Exit Sub
End If
If Me.cboRoleList = "Other" And Me.txtCustomRole = "" Then
MsgBox "Please provide a role name.", vbExclamation, "Other Role"
Exit Sub
End If
If Me.cboRoleList.Value = "" Then
MsgBox "Please select a Role.", vbExclamation, "Member Role"
Me.cboRoleList.SetFocus
Exit Sub
End If
If Me.cboRoleList <> "Other" And Me.txtPercent = "" Then
MsgBox "Please select a valid percentage to be applied to this sprint.", vbExclamation, "Sprint Percent"
Me.txtPercent.SetFocus
Exit Sub
End If
If Me.txtPercent.Value > 100 And Me.txtPercent <> "" Then
MsgBox "Please select a valid percentage to be applied to this sprint.", vbExclamation, "Sprint Percent"
Me.txtPercent.SetFocus
Exit Sub
End If
If Me.txtVacation.Value = "" Then
Me.txtVacation.Value = 0
End If
Dim i As Long
Set Prj = Worksheets("Project Team")
Set Bud = Worksheets("Budget")
Prj.Activate
i = 5
x = 1
If Me.cboRoleList.Value = "Other" Then
i = 46
End If
While Prj.Cells(i, 1) <> ""
i = i + 1
Wend
If cboRoleList = "Other" Then
Cells(i, x).Value = txtCustomRole.Value
End If
If cboRoleList <> "Other" Then
Cells(i, x).Value = cboRoleList.Value
End If
x = x + 1
Cells(i, x).Value = txtName.Value
x = x + 1
If Me.cboRoleList.Value <> "Other" Then
Cells(i, x).Value = txtPercent.Value
End If
Unload Me
End Sub
Private Sub CloseBut_Click()
Unload Me
End Sub
Change the event driven Worksheet_SelectionChange to Worksheet_Change and isolate further by only processing when something changes in A3:A49.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A3:A49")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim c As Range
For Each c In Intersect(Target, Range("A3:A49"))
c.EntireRow.Hidden = CBool(c.Value = vbNullString)
Next c
End If
safe_exit:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Caveat: A Worksheet_Change is not triggered on the change in a cell from the cell's formula. Only by typing, deleting or dragging a cell's contents. Adding or removing a formula will trigger it but not when a formula's result changes from another value somewhere in the workbook changing. This should not affect you as no formula can return vbNullString but it is worth mentioning for others.

How to get the MS Word Form Fields Check box associated text and their value using VBA?

How to get the MS word document checkbox form element associated text value. I am able to extract the value of the checkbox. I tried with bookmark and name properties and found that there is no value associated with bookmark filed of the checkbox. I got the following output. Any thoughts?
Form Fields:
Code:
Sub Test()
Dim strCheckBoxName As String
Dim strCheckBoxValue As String
For i = 1 To ActiveDocument.FormFields.Count
If ActiveDocument.FormFields(i).CheckBox Then
strCheckBoxName = ActiveDocument.FormFields(i).Name
strCheckBoxValue = ActiveDocument.FormFields(i).CheckBox.Value
Debug.Print strCheckBoxName & " = " & strCheckBoxValue
End If
Next
End Sub
Output:
Check1 = True
Check1 = True
Check1 = True
Check1 = False
Check1 = False
Check1 = False
Solution looking for:
A = True
B = True
C = True
D = False
E = False
F = False
EDIT:
By default, when a FormField Check Box is added, it has a Bookmark (name) of Check# where # is sequential starting at 1 until n. Copy and Paste are your friends with FormFields, so one of two things will occur if you go that route to get, say your 1000 FormFields:
1: If you do not alter the value of Bookmark (e.g. default to Check1) and copy and paste that say 1000 times, you end up with 1000 FormFields of Bookmark Check1.
2: If you alter the value of Bookmark (e.g. to A) and copy and past that say 1000 times, only the first FormField retains the Bookmark of A while the rest have a Bookmark that is empty.
You can alter the Check Box default bookmark value (in this case Check1 as a result from copy and paste over and over) to a sequential value such as A1, A2, A3, A4 or Check1, Check2, Check3, etc... by using the following:
Sub Test()
Dim strCheckBoxName As String
Dim strCheckBoxValue As String
For i = 1 To ActiveDocument.formFields.Count
If ActiveDocument.formFields(i).CheckBox Then
strCheckBoxName = ActiveDocument.formFields(i).Name
strCheckBoxValue = ActiveDocument.formFields(i).CheckBox.Value
Debug.Print strCheckBoxName & " = " & strCheckBoxValue
End If
Next
End Sub
Sub RenameCheckBox()
Dim oFields As formFields
Dim oVar As Variant
Dim i As Long
Dim x As Long
x = 0
i = 0
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
Set oFields = ActiveDocument.formFields
For x = 1 To oFields.Count
oFields(x).Select
Select Case oFields(x).Type
Case wdFieldFormCheckBox
oVar = oFields(x).CheckBox.Value
i = i + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "Check" & i
.Execute
End With
oFields(x).CheckBox.Value = oVar
Case Else
'Do Nothing
End Select
Next x
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Call Test
End Sub