I recently posted the topic Manipulating content in Microsoft Word with VBScript or VBA and received tremendous help solving my issue. Spurring off of this topic, I need to be able to use what I have learned and incorporate a new task.
I have a document similar to the one in the link above. However, the only difference is there are checkboxes being used and the code needs to select/deselect according to the user's choice. Here is the code I have so far:
Sub Check_Document()
objWord.Visible = True
Set objDoc = objWord.Documents.Open(UserProfile & "\Desktop\lettermiscreason - original.docx")
Set objRange = objDoc.Bookmarks("TodaysDate").Range
objRange.Text = TodaysDate
Set objRange = objDoc.Bookmarks("ProvName").Range
objRange.Text = ProvName
Set objRange = objDoc.Bookmarks("ProvAddress").Range
objRange.Text = ProvAddress
Set objRange = objDoc.Bookmarks("ProvCity").Range
objRange.Text = ProvCity
Set objRange = objDoc.Bookmarks("ProvState").Range
objRange.Text = ProvState
Set objRange = objDoc.Bookmarks("ProvZip").Range
objRange.Text = ProvZip
Set objRange = objDoc.Bookmarks("Check6").Range
If objRange.Value = False Then
objRange.Value = True
End If
Set objRange = objDoc.Bookmarks("Check5").Range
If objRange.Value = True Then
objRange.Value = False
End If
Set objRange = objDoc.Bookmarks("ProcInit").Range
objRange.Text = ProcInit
End Sub
Check6
is the checkbox I want to select and Check5
is the box I want to deselect. With the code as it sits, I get an error saying: Microsoft VBScript runtime error: Object doesn't support this property or method: 'objRange.Value'
. They show as bookmarks when I look at the rest I've used to enter data. Any suggestions? Should I be using something other than objRange
or can I use that but use something other than .Value
?
Aucun commentaire:
Enregistrer un commentaire