Complex Excel Formula - vba

I have what might be a strange formula I need to create in Excel and not sure how to accomplish this.
I have a value in one worksheet that I want to pull into another cell in a separate worksheet. This part is easy. What I want to do though is have a leader text before that content is pulled in (in the same cell). So far I think this is easy too. Now the complicated part. I want the leader text to be one color and weight and the text pulled in from worksheet 1 to be a different color and weight.
Any thoughts? So it might look like this:
From: Brian's Business
Where "From:" is Red and Bold and "Brian's Business" is Black and normal weight.
Any ideas on how I can accomplish this task?
Thanks in advance.
Brian

This is what I did with the VBA macro, you can do the same thing and adopt it to your needs
Sub Macro1()
Range("F28").Select
ActiveCell.FormulaR1C1 = "hjkljhklhjkl : ddfff"
With ActiveCell.Characters(Start:=1, Length:=0).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=1, Length:=7).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16776961
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=8, Length:=2).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=10, Length:=11).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
End Sub

Related

How to make text red and then black again?

Sub MakeTextRed()
'
' MakeTextRed Macro
'
'
With Selection.Font
.Name = "+Body"
.Size = 16
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorRed
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.SizeBi = 16
.NameBi = "+Body CS"
.BoldBi = False
.ItalicBi = False
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
End Sub
Shortcut key is Shift+Alt+R
I want to make it first make text red and then if I press same shortcut again make the text black.
I do not have knowledge of VBA. Please provide logic or algorithm.
With Selection.Font
If .Color = wdColorRed then
.Color = wdColorBlack
else
.Color = wdColorRed
end if
End With
Sub toggleColor()
With Selection.Font
.Color = -wdColorRed * (.Color <> wdColorRed)
End With
End Sub
If color is not red then (.Color <> wdColorRed) = -1 (True as integer) and result = wdColorRed. Otherwise (.Color <> wdColorRed) = 0 (False as integer) and result = 0 (wdColorBlack)

Merging text from different cells and keeping the format

Is it possible to copy information from mutiple cells, to one cell and keep the formatting? as an example, I have A1=Hello (Green, bold font), A2, World (red font)
Want to have B2=Hello World (with words in different color).
Looking for a solution in Google Sheets, but as an alternative, Excel would also work
For example my activecell has word "bankeris", so I made first 3 letters one color and another 3 letters with other color. This code is via "Macro recording". So copy/paste will do same.
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16776961
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
With ActiveCell.Characters(Start:=4, Length:=3).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorAccent6
.TintAndShade = -0.249977111117893
.ThemeFont = xlThemeFontMinor
End With
Thank you Bankeris.
The solution I need is a bit different - the number of characters will be variable, I purely need to copy the format from the original cell.
To give a big picture - there is a table with approx 8 columns, each column will have its color, but the numbers of characters in the cell will be different. The goal if to create a sentence which will include information from the specified row...but the format of each word in the sentence needs to be the same as in the original table.
Potentially, this solution could be used, but the number of chars for each color would need to be identified from te original cell and put as a variable in the code

MS Word How to select hidden text

So I have a set of code that would select a specific range of text to be hidden and I need to have a macro that would select those hidden text and unhide them. However, I don't know how to select those hidden text without first displaying them. Is there a way to select hidden text while they're not displayed. I'm trying to create a dynamic template where if certain conditions are selected only certain text will appear. So far this is my code to unhide hidden text.
Sub Macro2()
'
' Macro2 Macro
'
'
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=4, Extend:=wdExtend
With Selection.Font
.NameFarEast = "+Body Asian"
.NameAscii = "+Body"
.NameOther = "+Body"
.Name = "+Body"
.Size = 11
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
End Sub
The hidden text has to be visible on the screen to be selected. So you need this in your code. You don't need to un-hide them;
ActiveDocument.ActiveWindow.View.ShowHiddenText = True
If you want the user to not see the texts while running this may do the job. However, it is not tested;
Application.ScreenUpdating = False
Remember to turn it back on at the end of your code;
Application.ScreenUpdating = True

Place a button and assign a macro to it

I have the following code to create a button.
ActiveSheet.Buttons.Add(264, 230.25, 127.5, 11.25).Select
Selection.OnAction = "choose_worksheet_1"
Range("C16").Select
ActiveSheet.Buttons.Add(264, 230.25, 127.5, 11.25).Select
Selection.Characters.Text = "Next step (2)"
With Selection.Characters(Start:=1, Length:=13).Font
.Name = "Tahoma"
.FontStyle = "Standaard"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
'.ThemeColor = 2
'.TintAndShade = 0
'.ThemeFont = xlThemeFontNone
End With
This all works but the thing is that I would like to add a macro to it straight away. Could anybody tell me how I can a macro to the button, for example "Macro2"

Word 2010 VSTO Spacing Font Property - is it available in API?

Is it possible to access this option in VSTO:
Right click on paragraph -> Font -> Advanced Tab -> Spacing Option
and change it?
I believe so. These are the different parameters with which you can interact.
Sub Sample()
With Selection.Font
.Name = "+Body"
.Size = 11
.Bold = False
.Italic = False
.Underline = 0 ' wdUnderlineNone
.UnderlineColor = -16777216 'wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = -16777216
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = -1.1
.Scaling = 150
.Position = 4
.Kerning = 0
.Animation = 0 'wdAnimationNone
End With
End Sub