powerpoint 2010 vba - noncontiguous text selection - vba

I would like to select all characters in a Powerpoint textbox (Version 2010) that have a certain defined style (e.g. all bold characters). Manually, one can create a non-contiguous text selection in a single text box by simply holding the control key while selecting. With VBA, I failed so far. This is my very simple approach:
Dim c As TextRange
For Each c In ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange.Characters
If c.Font.Bold Then c.Select
Next c
While this all works nicely when going through this stepwise, the c.Select will always "unselect" what was selected before and there is no option to extend the selection (unlike with shape selections). I end up with just the last bold character being selected.
The selection itself is what I want as end result to give the user the option to further modify the font etc.
Does anyone have a suggestion (or is this not at all accessible via VBA?)
Thanks a lot

Related

Powerpoint VBA to search for and change colour/highlight keywords in textbox

I am very new to VB and am exploring this method to simplify mundane manual work process of highlighting certain text in Powerpoint textboxes.
My intention is for VBA to search for keywords in the textbox, then changes the colour of this line and also a few other lines. e.g. search for the line that contains the word "video", if it returns that line 7 contains this word, I want to change the colour of line 7 and maybe lines 3, 10 and 11 to red colour.
Since your question is generic, We can only give a generic response.
First thing you need to know about VBA in powerpoint for your issue is that you need to access things like objects. You'll first need to access the current Slide and Shape your textbox is in. In this example, Let's assume the textbox you want to access is in the first slide, in the first shape:
Set oTextbox = ActivePresentation.Slides(1).Shapes(1)
With oTextbox
text = .TextFrame.TextRange.Characters.Text 'To access the textbox text.
If InStr(1,text,"some_text")
.TextFrame.TextRange.Font.Color.RGB = [255 0 0] 'To change the color of a textbox.
End If
End With
.TextFrame.TextRange.Characters.Text accesses the shape's text.
To search for a given text in the textbox, you can use the InStr
command to see if the text you want is in your textbox.
.TextFrame.TextRange.Font.Color.RGB accesses the text's color.
This is at least a start for you.

How do I hide select text in excel (getting weird cells with conditional formatting)

How do hide cells that contain text in excel? These cells I am manually entering numbered data into them. I'd like them to be invisible when containing SetNumber but when I enter data manually, the data is visible.
I have seen a number of vba solutions and this solution which did not work. My question is how do I hide columns A, B and C which all contain SetNumber?
I have used conditional formatting but for some reason the output appears very un-natural. Is there a simple alternative?
To complete my comment above, you can do (in VBA):
Dim celltxt As String
celltxt = ActiveSheet.Range("A1").Text
If InStr(1, celltxt, "SetNumber") Then
Range("A:A").EntireColumn.Hidden = True
EndIf
To hide Column A based upon the contents of cell A1. You should be able to modify this to suit your needs.

Convert automatic numbering and bullets to plain text

I have a word document with automatic numbering and bulleting.
I have selected the text where I need to convert automating numbering and/or bulleting to normal text.
In addition I need to keep both the formatting and numbers/bullets of the selected text.
What I have already tried:
cut the paragraphs and special pasted them (but it breaks formatting);
unpressed the "numbering"/"bulleting" button (but it erases all numbers and bullets);
used VBA-macro (but it returns an error):
Code (error, method or data member not found):
Sub convertNumbersAndBulletsToText()
Selection.ConvertNumbersToText
End Sub
What would you recommend me to do in order to keep both formatting and numbers/bullets?
You have practically done everything yourself!
This code will work:
Sub convertNumbersAndBulletsToText()
Selection.Range.ListFormat.ConvertNumbersToText
End Sub
Your example returns error because ConvertNumbersToText method doesn't work with Selection. It works with Range!
(look here: Change selected automatic numbered list to plain text in word)
Beware!
If you want to carry out many changes, you may find it easier to make them with ActiveDocument (look below).
But if want to do it manually (or through a loop),
then you'd better loop from the last element you want to convert till the first one
(not vice versa, because auto-numbers would then increment by one all the time)!
Small Tips
Personally I would recommend you to use this code instead:
Sub convertNumbersAndBulletsToText()
Dim myRange As Range
Set myRange = Selection.Range
myRange.ListFormat.ConvertNumbersToText
End Sub
Why this one? It is a little bit more flexible! Instead of Selection.Range you could use any other type of Range (ActiveDocument, ActiveDocument.Paragraphs, myRange.SetRange etc)
Here are some links from msdn to give you basic examples of Ranges: 1) Range Object (Word) (msdn), 2)
Range.SetRange Method (Word) (msdn).
Just for your information, you don't need to save VBA if you don't want to. You can use Immediate Window to launch VBA.
Press alt+f11 (VBA-editor), then ctrl+g (Immediate Window).
Paste the code bellow, press enter.
VoilĂ !
Code (for Immediate Window):
ActiveDocument.ConvertNumbersToText
(It converts auto-numbers and auto-bullets to normal numbers and bullets everywhere in ActiveDocument).
The result of any VBA here would be number+tab+text. If you want to have number+space+text you can:
either at the very end replace (press ctrl+h) this one .^t (dot and tab) for . (dot and whitespace),
or at the very beginning 1) select the list, 2) right click on it, 3) click "Adjuct list idents", 4) click "Follow number with: Space". (Look here: Adjust the spacing for a single list item (support.office))
You may need to have a leading zero in (auto-)numbering, then you can press ctrl+f9, write SEQ MyList \# "000" inside curly brackets, press alt+f9 to finish (look here: Insert fields in Word (support.office)). But this goes beyond the question, though you may find word fields really useful in some cases.
To sum up:
You can replace both bullets and numbers for plain text in Word:
for Selection (look above);
for ActiveDocument (look above);
with a Range (examples in msdn);
with a loop (examples are welcomed). But bear in mind that you are to loop from the end of the document to the beginning.

VBA for changing font and colour of a cell if a certain word is typed in it

I have a somewhat large spreadsheet with a type of summary page that follows a calender layout.
On this page I manually change the font and color of cells to make it easy for me to find certain things on it. For example, (I lecture mathematics) if I have revision on a certain lesson, I make that cell bold and green. (exact type of green I can sort out myself). I want a VBA code if possible so that if I type the word revision into a cell on that sheet only, not whole workbook, that it would automatically change it to green.
Realistically, I don't manually type in the word revision always. Some of it uses lookups of various types to find what happens on that day to display a word (for example revision) in that given cell.
I don't know if this is possible to do. I realize that if "revision" is shown due to a lookup then the contents of that cell is not equal to "revision" but a formula which simply displays "revision"
Any assistance would be appreciated. If I have a basic code I can manipulate to get it right.
Thanks
Maybe you're looking for something along the lines of:
Sub CheckRevision()
Dim CurCell As Object
For Each CurCell In ActiveWorkbook.ActiveSheet.Range("A1:AZ500")
If CurCell.Value = "Revision" Then CurCell.Interior.Color = RGB(0,204,0)
Next
End Sub
Or equivalently, you can probably use conditional formatting. Home Tab > Conditional Formatting > Highlight Cells Rules > Text that Contains. From there, type the value "Revision" into the value box and you can change the format of the cell to how you like it.

Edit the style of all hyperlinks in a Word document

I have a word document that is littered with hyperlinks. The links themselves work fine, but for some reason, most of them are not blue anymore! All I'm really looking to do is try to find a way to use a macro or something to go through the document and add the "Hyperlink" style format to each hyperlink.
I tried to edit some macro code myself (one that changes all the links URLs), but I keep making the problem worse! I used to be good at VBScript, but it's been ages since then.
Any easy solution that doesn't involve manually changing each style?
As a side note, all of them currently are in "Normal" style, for some reason.
Try to execute this VBA script (best in debugging mode using the F8 key - have VBA and Word windows side by side so you can see what's happening):
Sub FormatLinks()
Dim H As Hyperlink
For Each H In ActiveDocument.Hyperlinks
H.Range.Select ' (A)
Selection.ClearFormatting ' (B)
H.Range.Style = ActiveDocument.Styles("Hyperlink") ' (C)
Next H
End Sub
This will
cycle through all hyperlinks in your document (A),
remove any formatting on the underlying text (B) and
assign the undrelying text to style "Hyperlink" (C)
(C) is not strictly necessary, as (B) should already sanitize your document, but maybe better to have hyperlinks really assigned to style "Hyperlink" because you may want to change the style later on.