• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Formating Excel Cells from VB.net

Friends,

I am wanting to format a series of cells with a the font style of "Times New Roman"

I did this code, and it compiles, but it doesn't change the font style as desired.

        With oSheet.Range("A1", "N1")
            .Font.Bold = True
            .HorizontalAlignment = excel.XlHAlign.xlHAlignCenter
            .Font.Italic = True
            .Font.Size = 12
            .Cells.WrapText = True
            .Font.FontStyle = "Times New Roman" '<--- Does NOT change font to Times New Roman.

        End With

Also, I want another set of cells to be set as currency, with negative values in Red and in ( )'s?

        With oSheet.Range("E3", "T" & NumberOfCarsInRace + 2)

            .HorizontalAlignment = excel.XlHAlign.xlHAlignCenter
            .Font.Italic = False
            .Font.Size = 8
            .Style = "Currency" '<---- This sets it to currency, but not with the option of having negative values in red and with ( )'s around the value
 
       End With

Thanks!
0
indy500fan
Asked:
indy500fan
  • 7
  • 5
1 Solution
 
PockyMasterCommented:
You are trying to set the fontStyle, which in my memory only is an enumeration of Bold, Italic and that kind of stuff
0
 
PockyMasterCommented:
If you want to create a new font you can use:
Dim myNewFont as  new Font ("Times New Roman", 12 )

.Font = myNewFont
0
 
indy500fanAuthor Commented:
PockyMaster,

Can you implement your suggestion with my existing code snippet.  As it is now, it is giving the error: 'New' cannot be used on an interface.

Also any suggestions for the currency part of my question?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
PockyMasterCommented:
With oSheet.Range("A1", "N1")
            .Font.Bold = True
            .HorizontalAlignment = excel.XlHAlign.xlHAlignCenter
            .Font.Italic = True
            .Font.Size = 12
            .Cells.WrapText = True
            .Font.Name = "Times New Roman"   '<-- this should work (worked on my machine :D)
        End With
and let me think about the currency part (never done that, but can have a look for you)
0
 
PockyMasterCommented:
You might find the following link useful, regarding the number style:
http://www.aspose.com/Wiki/default.aspx/Aspose.Cells/NumberFormat.html
0
 
indy500fanAuthor Commented:
PockyMaster,

Thanks for the help with the font.Name, but I'm still having trouble with the currency setting

According to the website you gave,

I should be able to say:

        With oSheet.Range("E3", "T" & NumberOfCarsInRace + 2)
            .HorizontalAlignment = excel.XlHAlign.xlHAlignCenter
            .Font.Italic = False
            .Font.Size = 8
            .Style.Number = 8 <--The program breaks and exits here!!!

        End With
0
 
Bob LearnedCommented:
If you are looking for Currency format, then:
   .Style = "Currency"

Bob
0
 
indy500fanAuthor Commented:
Bob,

I'm so embarrassed.  I forgot all about this one...

I am so sorry.

Best Regards,
Eric
0
 
PockyMasterCommented:
Uh, you're welcome ...
0
 
indy500fanAuthor Commented:
PockyMaster,

Doh! I forgot you helped me with the first part!  I should have split the points!  Can I fix that?
0
 
PockyMasterCommented:
It's ok :D
0
 
indy500fanAuthor Commented:
That's not funny :)

I'd just hate to tick you off and lose your help in the future.  You have been most helpful in the past and I am grateful of you help.
0
 
PockyMasterCommented:
Well, you didnt, it's ok...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now