473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Changing axis font with excel object embedded in VB6

Hi,

I have a chart that I created in excel through VB. I want to try and change the font name from Times New Roman to Symbol. I tried recording the macro in excel but when I use the code in VB it doesn't work. Here is what I got:

Expand|Select|Wrap|Line Numbers
  1. Dim xlApp As Excel.Application
  2. Set xlApp = New Excel.Application
  3. xlApp.DisplayAlerts = False
  4. Dim xlWkb As Excel.Workbook
  5. Set xlWkb = xlApp.Workbooks.Add
  6. Dim xlSht As Excel.Worksheet
  7. Set xlSht = xlWkb.Worksheets(1)
  8. Dim xlChart As Excel.Chart
  9. Dim MyShape As Shape
  10.  
  11. Set xlChart = xlWkb.Charts.Add
  12.  
  13. xlSht.Cells(8, 2) = 1
  14. xlSht.Cells(9, 2) = 2
  15. xlSht.Cells(10, 2) = 3
  16. xlSht.Cells(11, 2) = 4
  17. xlSht.Cells(12, 2) = 5
  18.  
  19.  
  20.  
  21. xlSht.Cells(8, 3) = 10
  22. xlSht.Cells(9, 3) = 20
  23. xlSht.Cells(10, 3) = 30
  24. xlSht.Cells(11, 3) = 40
  25. xlSht.Cells(12, 3) = 50
  26.  
  27.  
  28. xlApp.Visible = True
  29.  
  30. xlChart.SetSourceData xlSht.Range("H10"), xlColumns
  31.  xlChart.SeriesCollection.NewSeries
  32.   xlChart.SeriesCollection(1).XValues = "=Sheet1!R8C2:R17C2"
  33.   xlChart.SeriesCollection(1).Values = "=Sheet1!R8C3:R17C3"
  34.   xlChart.Axes(xlValue, xlPrimary).HasTitle = True
  35.   xlChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "p"
  36.   xlChart.Axes(xlValue, xlPrimary).AxisTitle.AutoScaleFont = True
  37.   xlChart.Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Symbol"
  38.  
  39.     xlChart.ChartArea.Select
  40.  
  41.     xlChart.ChartArea.Font.Size = 20
  42.     xlChart.ChartArea.Font.Color = vbRed
  43.  
  44.     xlChart.ChartArea.Select
  45.     xlChart.ChartArea.Copy
  46.  
  47.     Image1.Picture = Clipboard.GetData(vbCFBitmap)
The part in bold is where I try and change the font name.

Can anyone see what I'm doing wrong? This is really important so any help would be greatly appreciated.

Thanks
Jun 21 '07 #1
8 2635
Killer42
8,435 Expert 8TB
Can you give a more specific description of the problem than "doesn't work"? Do you get an error? If so, what one?
Jun 24 '07 #2
Can you give a more specific description of the problem than "doesn't work"? Do you get an error? If so, what one?
I don't get an error, nothing happens to the axis when I use the commands in bold.
Jun 25 '07 #3
Killer42
8,435 Expert 8TB
I don't get an error, nothing happens to the axis when I use the commands in bold.
Hm... but the rest of the code works?
Jun 25 '07 #4
Hm... but the rest of the code works?
Yes everything works great. Thats what is really bothering me because all I need to do is change the font of the X and Y axis titles but it just doesn't change.
Jun 26 '07 #5
Killer42
8,435 Expert 8TB
Yes everything works great. Thats what is really bothering me because all I need to do is change the font of the X and Y axis titles but it just doesn't change.
Very odd.

I don't know what the problem is, but as a workaround, perhaps you could create a Font object, set it the way you want, then assign it to the .Font property of the axis. I've seen this done, but don't have any experience with it.
Jun 27 '07 #6
Very odd.

I don't know what the problem is, but as a workaround, perhaps you could create a Font object, set it the way you want, then assign it to the .Font property of the axis. I've seen this done, but don't have any experience with it.
hmmm, not sure how to do it but I will look into it. Thanks!
Jun 27 '07 #7
hmmm, not sure how to do it but I will look into it. Thanks!
I seemed to have figured it out. Near the bottom of my code I am setting some ChartArea properties and I guess these properties are overriding the AxisTitle properties. If I get rid of that code then the AxisTitle properties work.
Jun 27 '07 #8
Killer42
8,435 Expert 8TB
I seemed to have figured it out. Near the bottom of my code I am setting some ChartArea properties and I guess these properties are overriding the AxisTitle properties. If I get rid of that code then the AxisTitle properties work.
Cool! If it turns out you still need the ChartArea stuff, perhaps you can just change the order in which you set them or something.
Jun 28 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: stainless | last post by:
I am currently designing a .NET system that takes a piece of text from a SQL Server database (this is variable), writes it to an excel spreedsheet in a cell of known length and height (in...
2
by: Colleyville Alan | last post by:
I have been working on an application that queries data from Access, loads it into an array, and then writes it to an Excel spreadsheet. I use the array approach to have fine control over spacing,...
3
by: Jeff | last post by:
Hi I have a report with a graph on it and want to change the minimum and maximum values for the value axis when it is previewed. This can't be done by adding code in the Open event as once the...
3
by: Jeff | last post by:
Hi I am manipulating MS Graph and can successfully change the minimum and maximum values for the Y axis, but can't find a way of doing this for the X axis. This works for Y axis...
4
by: BerkshireGuy | last post by:
I have the following Access code that exports to Excel, inserts a title, changes the color of the title, and then changes the format of several columns to currency. The following code sometimes...
3
by: Claus Haslauer | last post by:
Hi, I want to create a chart value (y-axis) vs. time (x-axis). In fact very similar to the xy(scatter) example in the graph10.chm help-file. I ran into problems, so I started a very basic *.mdb...
0
by: Marcin Zmyslowski | last post by:
Hello all! I have the following problem. I would like to move the x axis values from my chart. The X Axis Values are very near the x axis, that`s why I want to put a space between the x axis...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
11
by: Noel | last post by:
Hi all, I'm trying to create a 3D graph, which has 3-axis with different labes. I need to be able to color each of the bars indervidually. Something like that in excel, i.e. x- axis (species),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.