In slide 1, a textbox that says "Report For 07/26/2022 (12:00am to 11:59pm local time)" the textbox that has this phrase has the name "Rectangle 13"
I want to be able to update the date with vba. I want to keep the same formatting (i.e. the bold on the last part of the phrase)
I am guessing that I will need to do an inputbox to create a variable NewDate. the NewDate would be a string. then the NewDate would be updated in the textbox.
I am just unsure of the exact code
Related
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.
I have a userform I am making. An input box will open and the user will enter a month. Then The userform will open, inputting that month into textbox3. I want text box 1 to be 1&the number form of that month. I have tried several types of code but i am fairly new to vba.
Help would be appreciated.
Here is the code i have tried.
TextBox1=MONTH(DATEVALUE("1"&TextBox2.value))
With December in TextBox2, use,
TextBox1 = "1" & Month(DateValue("1-" & TextBox2.value))
TBH, I really wouldn't trust my users to spell the month name correctly but have them select from a list instead.
I have a user input box where you type in a string, annoyingly this string looks like a date 00/00/0000 and excel reformats it as such.
When the value can't be a date ex. 18/19/4561 (month can't be 18 or 19) it displays it correctly.
But whenever it can be seen as a possible date it switches things around.
I've tried setting the value as a string rather than nothing but excel still changes it when putting it in the page.
When I try manually inputting it in the cell or equal the values from a manually entered cell it works fine.
But whenever I get it from the inputbox it messes with it. Even when I hard code the string to a variable (x = "05/06/4564") it switches things around.
How do I force excel to leave the string as is?
Prefix the value with a single apostrophe and Excel will interpret it as a string.
Eg '18/19/4561
Also, have you tried setting the cell format to Text
I've a problem with this VBA macro.
Sub demoChangeText()
Application.Range("B2").Value = "Overidden text"
End Sub
My test is here. To run this macro, open it in Excel, press Ctrl+F8 and choose demoChangeText.
As the result, this macro changes the value of cell B2 (the text displayed to us) but clear its formula. I need to change B2's value BUT also need the formula to be remained.
So my question is How to change the display text of cell without changing its formula?
UPDATE
I ask this question because I'm trying to solve this problem
I'm not sure if this will help, as it is a bit hard to tell what your underlying requirement is, but here goes anyway:
Several things affect the display of a cell:
the entered value, if its a constant
the result of a calculation, if its a formula
the format of the cell
the conditional format(s) of the cell, if any
In the example sheet provided you have a formula of =ROW()&COLUMN() which returns a string result of 22
You can make this display something else by applying a cell format,
eg a format of 0;0;0;Ov\e\r\ri\d\d\e\n t\ext will display any string value as Overridden text
This can by applied with VBA with
Range("B2").NumberFormat = "0;0;0;Ov\e\r\ri\d\d\e\n t\ext\s"
or
Range("B2").NumberFormat = "0;0;0;""Overridden texts"""
How to find enter and space in the excel cell value by uisng VBA. For example if the cell value contain value like "Some value" then How to find that this cell contain space. In second case if the cellvalue contain Enter like while typing values in a cell if someone write "Some" and the press enter and then write "value" then how to find this enter.
I am using excel 2007
Thanks
You can't hit enter to get a new line in Excel, you have to hit alt + Enter. You can use the VBA constant vbLf in your Instr to find it.
Jesse