Using VBA how does one return a "frame" index?
I have a number of frames that I would like to assign code to and have the code select specific code based on the frame selected. Similar to Excel's "select case".
Your advice is appreciated.
Frame index
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Frame index
Regards,
John
John
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Frame index
Hans,HansV wrote:The selected frame is Selection.Frames(1)
So if I have 10 frames the index for each frame would be: Selection.Frames(1), Selection.Frames(2) and etc.?
Would the VBA code to identify the frame index then be: Msgbox Selection.Frames.Index ? The returned value would be 1, 2, 3,.... 10.
Regards,
John
John
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Frame index
Do you really need the index of the selected frame, or do you need the selected frame object itself?
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Frame index
Hans,
I created "frame 1" with checkboxes (Yes/No) and assigned VBA code to the "Entry" field option of each checkbox. The code (found it online) works great but does not work on the other frames.
I created "frame 1" with checkboxes (Yes/No) and assigned VBA code to the "Entry" field option of each checkbox. The code (found it online) works great but does not work on the other frames.
Code: Select all
Sub MakeCheckBoxesExclusive()
Dim oField As FormField
For Each oField In Selection.Frames(1).Range.FormFields
oField.CheckBox.Value = False
Next oField
Selection.FormFields(1).CheckBox.Value = True
End Sub
Regards,
John
John
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Frame index
It appears to work for me. I have attached a very simple sample document with two frames, each with three check boxes. Your macro has been assigned to each of the check boxes.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Frame index
Hans,
What version of Word are you using? I'm on 2010.
Is it possible to have the frame inside a table cell? I copied the frame and pasted it into the table cells. It appears that only the objects of the frame were pasted.
What version of Word are you using? I'm on 2010.
Is it possible to have the frame inside a table cell? I copied the frame and pasted it into the table cells. It appears that only the objects of the frame were pasted.
You do not have the required permissions to view the files attached to this post.
Regards,
John
John
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Frame index
I'm using Word 2019.
You cannot have a frame inside a table cell. A frame is a floating object.
You cannot have a frame inside a table cell. A frame is a floating object.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Frame index
Hans,
Since the two checkboxes are in table cells can the code be modified accordingly?
Since the two checkboxes are in table cells can the code be modified accordingly?
Regards,
John
John
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California