Focus cursor in a bubble comment created with VBA - vba

I add a new comment in VBA.
Initial = ActiveDocument.ActiveWindow.View.SplitSpecial
Selection.Comments.Add Range:=Selection.Range
ActiveDocument.ActiveWindow.View.SplitSpecial = Initial
This displays the comment in the right margin in a "bubble". The text entry point remains in the document.
How can I get the text entry point inside the comment bubble?
NOTE: If I use SendKeys to add the comment using the ribbon controls, the text entry focus is inside the comment bubble, but I'd rather not use SendKeys as that is liable to go wrong at times.

The most efficient way is to declare a Comment object and initiate it at the time the comment is created in the document. Note, also, that Comments.Add has a parameter for adding text when it's created.
Please also note that the window switching is unnecessary unless you specifically want/need the old Word 2.0 "pane" view (from the time before WYSIWYG existed).
Example:
Dim cmt As Word.Comment
Set cmt = ActiveDocument.Comments.Add(Selection.Range, "test")
cmt.Range.Text = cmt.Range.Text & " More text."

Related

Word VBA SelectContentControlsByTag collection out of order?

I'm working on a Word template form using ContentControl fields for drop down lists. I made a macro to take each content control tagged "required" and check if it's showing placeholder text. If it is, it throws up a message box asking the user to fill in the required fields, and IDEALLY jumps to the bookmark for that content control box.
After a lot of iteration and troubleshooting, it can in fact do that, but I've noticed that the Collection of required fields is in..... a random order. I tested this by adding another content control dropdown named "jimmy" at the bottom of the Word document and then looked in the collection and saw it was in the middle of all the other required fields.
Does anyone know how the "SelectContentControlsByTag" method decides on its order, and if there's a robust way to make it use the order that they're placed in the document? I have a decent amount of coding experience but I'm entirely self-taught as far as VBA goes, so I'd appreciate the help!
Here is my current code (Doc is set in Document_New, and the bookmark jump isn't in currently, I'm just checking the order in VBA/the message box)
Set reqFields = Doc.SelectContentControlsByTag("required")
For Each iField In reqFields
If iField.ShowingPlaceholderText Then
Dim Msg, Style, Title, Response
Msg = "The dropdowns marked with * cannot be left blank. Do you want to select a response before exiting? Box: " & iField.Title ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton1 ' Define buttons.
Title = "Warning: Empty fields" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Doc.Saved = False: SendKeys "{ESC}"
'iField.Range.Select
Exit Sub
End If
'Exit For
End If
'Exit Sub
Next iField
Sorry for being 10 months late in answering!
When you use .selectcontentcontrolsbytag VBA will loop through the existing content controls by .ID to pull out the tag name. So if you want your ("tag").item(1) to be ordered you first need to put your content controls in ascending order by .ID number.

Uncheck "Formatting" in MSWord tracked changes Markup Options? (Office 365 for Mac v16.26)

I want to use an AutoOpen() sub for all docs to (1) turn on tracked changes [this part is successful] and (2) stop Word from displaying formatting changes in the sidebar. Word defaults to displaying all comments and formatting in balloons, which is what I want, but I don't actually need to track or review formatting changes.
See ![screenshot]https://imgur.com/a/28ARVob for a screenshot of what I want to accomplish automatically via Macro. When I choose Record Macro, uncheck Formatting, and stop recording, no code has been generated in VBE. There doesn't seem to be an available property in VBA for Word (Mac or otherwise) that will accomplish this goal.
Here's my current AutoOpen() code:
Sub AutoOpen()
ActiveDocument.TrackRevisions = True
With ActiveDocument
.TrackFormatting = False
End With
End Sub
Turning off tracking formatting, as I'm currently doing, only works going forward, so all existing changes will still be displayed until I uncheck the Formatting option. It's a partial solution, at least.
I'm also aware there is a property to show/hide revisions as a whole (i.e. I could include the code: .ShowRevisions = False), but that's not quite what I'm looking for here, since I only want to hide the formatting (I would expect it to be something like .ShowFormatting, but that is not a property in VBA).
Any thoughts/suggestions are welcome.
Those settings are in a different part of the object model, under the View object. Here's a code snippet that shows how to turn off the display of tracked changes. Note that this doesn't remove them from the document, it only supresses the display. In order to remove these revisions from the document it would be necessary to accept or reject the changes.
Dim doc As Word.Document
Set doc = ActiveDocument
doc.TrackRevisions = True
doc.TrackFormatting = False
doc.ActiveWindow.View.ShowFormatChanges = False

how to clear a picture content control with macro in ms word

I have created a form where the user has the option to reset (clear) the form. I was able to clear everything from the form (textbox's, combobox's & checkboxes), but not sure how to clear a picture if one was inserted without deleting the entire option. I've tried using the bookmark method,however, with not success. the bookmark is selected then delete. Which cause the code not to recognize the Inlineshape (hence - Run-time error '5941 "the requested member of the collection does not exist".
ActiveDocument.Bookmarks("picture").Select
Selection.InlineShapes(1).Delete
Selection.InsertAfter ""
You code makes no mention of content controls, however
Dim oCC As ContentControl
Set oCC = ActiveDocument.SelectContentControlsByTitle("Picture1").Item(1)
If oCC.Range.InlineShapes.Count > 0 Then oCC.Range.InlineShapes(1).Delete
where 'Picture1' is the title of the picture content control, should do the trick.

Accessing ScreenTip text

I have a long MS Word doc that has many bookmarks/hyperlinks. The only purpose of the bookmarks is to be able to use the screen tips to view additional information about what is bookmarked.
Is there a way to access this screen tip text, and store it in a variable?
Eventually I will use this to create a macro that will change the displayed text to include the screen tip text (so the information can be printed, when necessary).
Here's how to print-to-console all the Hyperlink ScreenTips in your document:
Sub printScreenTips()
Dim link As Hyperlink
For Each link In ThisDocument.Hyperlinks
Debug.Print link.ScreenTip
Next
End Sub
Note: I'm not aware of a way to add a ScreenTip to a bookmark, but you can add a ScreenTip to the hyperlink that points to a bookmark.

Validating Attachment in Richtext field

I am using below code to validate the Attachment in Richtext field.
If I will not used Call source.Refresh(True)
then validation is not working, but this code is also refreshing document everytime querysave is called in buttons.
So is there any option or any other idea so that I should not user this Refresh part or entire code to validate .
If anybody have more efficient code then please share this.
If Source.Document.YesNo20(0)="Yes" Then
Call source.Refresh(True)
Dim rtitem As NotesRichTextItem
Set rtitem = source.Document.GetFirstItem( "Atchmnt20" )
NotesEmbeddedObjectArray = rtitem.EmbeddedObjects
If Isempty ( NotesEmbeddedObjectArray ) Then
Messagebox "Please enter an attachment in 20a. As you selected option Yes"
continue=False
Exit Sub
End If
End If
There's a way in LotusScript to check attachments presence even for new (not saved) documents.
Create a hidden computed field, for instance AttachmentNames with formula:
#If(#AttachmentNames!=""; "1"; "");
In LotusScript do the following:
'in new documents Form field may be empty
If doc.Form(0) = "" then
doc.Form = "YourFormAlias"
End If
'computing doc contents with the form
call doc.ComputeWithForm(false, false)
If doc.AttachmentNames(0) = "" then
MsgBox "Please attach a file",,"Attention"
Continue = False 'if you are running this code in QuerySave
Exit Sub
End If
Validating rich text fields in Lotus Notes is a bit of a dark art, but can you not just do this? (where doc is the back-end):
If(doc.HasEmbedded) Then Continue = True
There are other things you can do. Check this Lotus Developer Domain post, which covers attachments, text, embedded objects, all sorts:
http://www-10.lotus.com/ldd/nd6forum.nsf/0/8b3df10667d355768525719a00549058
Can you validate RT field with formula?
I created a hidden field below my rich text field with this Input Validation formula:
REM {Validate just when saving};
#If(!#IsDocBeingSaved; #Return(#Success); "");
REM {Should contain some file};
_filenames := #AttachmentNames;
#If(
#Elements(_filenames)=0;
#Return(#Failure("You should attach at least one file"));
#Success);
Assuming that you want to avoid the Refresh because it takes too long, here is what you may want to look at and if feasible, try to change:
Maybe you can use the "Entering" event of the RichText field in conjunction with a global variable (in the form) to skip the Refresh in your code, if the RichText field wasn't touched at all.
Are there keyword fields with "Refresh choices on document refresh" option enabled that may be safe to disable? Or even place a button that would bring up a dialog and populate the field with the selected keyword(s) - refreshing the choices won't be neccessary then, as you can always present up-to-date choices through #DbColumn/#DbLookup or NotesUIWorkspace.PickListStrings.
Is there any code (LotusScript or Formula) in "Queryrecalc" and/or "Postrecalc" form events that may be possible to optimize? For example by using a global variable (in the form) as a flag whether to execute the code in Queryrecalc/Postrecalc - set it to false just before calling Refresh in your code, then set it back to true (because this Refresh only serves to update the RichText field to the backend document).