2

I am trying to copy a font style from one range to another using the following code:

Range("A10").Font.FontStyle = Range("A11").Font.FontStyle

Normally it would work in a way that it extracts the name of the font style which is "Bold" from Range "A11" and uses it to set the font style of Range "A10".

However because the language of my Excel is set to Polish, instead of "Bold" it extracts the Polish name of the font style ("Pogrubiony"). Because of that, the code does not work since VBA accepts only English names (as far as I know).

I know I could do something like this:

if Range("A11").Font.FontStyle = "Pogrubiony" Then Range("A10").Font.FontStyle = "Bold"

But I'm wondering if there is a way for VBA to convert the name to English automatically or maybe recognise the name of font style if it's in different language?

Dawid
  • 47
  • 5
  • If all you're checking for is **Bold**, then you could opt to use `If Range("A10").Font.bold = True Then Range("A11").Font.bold = True` instead, checking with the `.bold` property in VBA rather than the font style name. This can be done for most formatting options. – Plutian Nov 08 '19 at 09:53
  • Other than that, you're likely to be looking at [options like this](https://stackoverflow.com/questions/19098260/translate-text-using-vba) using google translate. – Plutian Nov 08 '19 at 09:57
  • @Plutian I also want to check for the Italic style but that's still a nice solution. Thanks – Dawid Nov 08 '19 at 10:05

1 Answers1

1

Have you checked the Font.Bold Property and Font.Italic Property?

You could do something like

Sheet1.Range("A11").Font.Bold = Sheet1.Range("A10").Font.Bold
Sheet1.Range("A11").Font.Italic = Sheet1.Range("A10").Font.Italic
Nacorid
  • 783
  • 8
  • 21
  • Thanks, that's quite a good idea. I wanted to use .Font.FontStyle because it copies both, the bold and italic styles ("Bold Italic") which means that I have to use only one line of code but this one is good too. – Dawid Nov 08 '19 at 09:59
  • Iirc the `Font.FontStyle` "Bold Italic" simply sets `Font.Bold` and `Font.Italic` to `True` – Nacorid Nov 08 '19 at 10:06