Delete All Text After Bookmark - vba

I am running a script on a word doc that generates a bunch of text. I have a button that I would like to be able to use to clear all of the text. How can I delete all text after a bookmark?

That's as simple as:
With ActiveDocument
.Range(.Bookmarks("MyBookmark").Range.End, .Range.End).Delete
End With

Related

Jump to found text in document

I am programming a loop which searches for highlighted text in a document.
If a text is found it should be shown in the Word window similar to the non-vba search function that you have in word.
How can I achieve this?
Here is the code that I use to find the highlighted text, and it works well.
But I don't now how to show the found instances in the word document.
With ActiveDocument.Range
.Find.Highlight = True
Do While .Find.Execute
' Jump to found text and prompt user to take action.
Loop
End With
PS: Once an occurrence is found, I want to prompt the user via to take action on this part of the text. The context is important for the user to decide, therefore he has to see the text. I'm clear on the prompting part, but I cannot figure out how to show the text to the user.
You need to use the .Select method. I'd recommend doing this on a .Duplicate of the current found range. e.g. Inside your do loop use '.Duplicate.Select' (NOT .Find.Duplicate.Select)

Combining Rich Text Content Control Content in MS Word using VBA

I'm trying to create a form for a non-technical user in MS Word to capture some text content in MS Word. This word doc consists of several rich text content controls where the user will type in or paste in some formatted data (bold, underlined, links, ...).
Once they get all the content entered into these various content controls I'm trying to make it easy for them to combine them together to paste in a consistent order into some podcast show notes which is in an HTML form.
So basically, I want to take three rich text content controls that have formatted data in them, combine them together into one formatted piece of content, and then copy it to the clipboard so they can then go to this web form, paste it in, and do some minor cleanup. The problem is that whenever I try to combine the RTF content it loses the formatting.
The only way I seem to be able to keep the formatting is if I copy the range object and then paste it. However, this doesn't paste just the formatted text. It pastes the whole rich text content control.
I've tried creating a blank RTF field at the bottom of the Word doc to combine everything in but I just can't figure it out. I wouldn't think this would be rocket science.
Being none of the code I've tried works and keeps the formatting I"m not sure if posting it here will do any good. Here's how I'm getting the value of the text object:
ActiveDocument.SelectContentControlsByTitle("txtShowNotes").Item(1).Range.Text
tried this:
ActiveDocument.SelectContentControlsByTitle("txtShowNotes").Item(1).Range.Copy
ActiveDocument.SelectContentControlsByTitle("txtCombinedContentSection").Item(1).Range.Paste
but this copies the whole RTF and not just the text.
Try something based on:
Sub Demo()
Dim Rng As Range
With ActiveDocument
Set Rng = .SelectContentControlsByTitle("txtCombinedContentSection").Item(1).Range
Rng.FormattedText = _
.SelectContentControlsByTitle("txtShowNotes").Item(1).Range.FormattedText
Rng.InsertAfter vbCr & vbCr
Rng.Characters.Last.FormattedText = _
.SelectContentControlsByTitle("txtShowNotes").Item(2).Range.FormattedText
End With
End Sub

How to append html contents into word using outlook vba

I am trying to append contents of a html document(with formatting) at the end of a word document (which already has some contents in it). I am using vba in outlook. Please help. Thanks in advance.
Create a range at the end of the document, then call Range.insertFile.

MS Word Macro to replace all hyperlinks with a single word

I prepare a MS Word file with a large amount of news articles, each followed by a full, long clickable hyperlink (e.g. http://www.newssite.com/this-is-the-name-of-the-article.html).
I need to replace all the hyperlinks in the file with a single word: "Link", while keeping their url adresses and click functionality. I can use MS Word "change hyperlink" dialogue to do that, but doing it by hand takes incredible amount of time.
The hyperlinks, however, are not always formatted as 'hyperlink' style. Is there any condition for MS Word Macro replacement that will lookup hyperlinks by their functionality, not by their style or text?
Despite this task seems to be quite common, I could not find anything like it in the web.
Since you have the hyperlinks already created. It should just require looping through the documents hyperlinks collection and changing the 'TextToDisplay' property. This should get you started:
Public Sub ChangeHyperlinksText()
Dim hlink As Hyperlink
For Each hlink In ThisDocument.Hyperlinks
hlink.TextToDisplay = "Link"
Next hlink
End Sub

vb parse word from clipboard into html

I want to copy some word text with tables, links and images and paste it into a rich textbox in my vb project. Where I want to parse it to html.
The Questenion is, how can access the copied word in the clipboard. Using
My.Computer.Clipboard.GetText()
just returns text, without the structure for links, tables or images. But there have to be a way to access it, because my rich textbox seems to know the word format. When I paste it into it, tables, images and links are also displayed in there.
You can try to specify text format in GetText's parameter as follow :
Dim htmlText As String = Clipboard.GetText(TextDataFormat.Html)