Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 19th, 2006, 01:57 PM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default chart object as anchor for hyperlink

hi,
is there a way to use a chart object as an anchor for a hyperlink in vba? probably using the statement activesheet.hyperlinks.add anchor:=... and so on.
i believe shape objects can be used as anchors, and i am trying to refer to the chart object as a shape, but so far it has not worked.
any help will be very appreciated!
thank you,
kriti

Reply With Quote
  #2 (permalink)  
Old July 28th, 2006, 11:29 AM
Authorized User
 
Join Date: Jul 2006
Location: , , Poland.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default



Info from:

http://pubs.logicalexpressions.com/P...?ID=209#jon016

Hyperlink to a Chart

Hyperlink to an Embedded Chart

You can't hyperlink to a chart directly, but you can link to a cell on the worksheet in which the chart is embedded. Use the cell under the top left corner of the chart, or the entire range under the chart.

Hyperlink to a Chart Sheet

You can't hyperlink to a chart directly, and a chart sheet has no underlying cells you can link to. You can fake it with a Worksheet_SelectionChange event procedure, however. In this example, the hyperlink is in cell B2. Enter the name of the chart sheet in cell B2, and format it with blue underlined text, so it looks like a real hyperlink. Right click on the sheet tab, select View Code, and paste this macro into the code module that
appears:

  Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
      If Not Intersect(Target, Range("B2")) Is Nothing Then
           Cancel = True
      End If
  End Sub

  Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Not Intersect(Target, Range("B2")) Is Nothing Then
           On Error Resume Next
           Charts(Target.Value).Activate
           If Err.Number <> 0 Then
               MsgBox "No such chart exists.", vbCritical, _
                     "Chart Not Found"
           End If
           On Error GoTo 0
      End If
  End Sub

When the user selects cell B2, the procedure is activated. The code jumps to the sheet with the name in the cell. If it can't go to that sheet, it assumes it's because the sheet doesn't exist, and it alerts the user.


Reply With Quote
  #3 (permalink)  
Old July 28th, 2006, 03:25 PM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
thanks so much for your reply, but i need to hyperlink FROM a chart, not TO chart. i.e., i need the chart to be the link, not the destination of the link. any thoughts in that area?
kriti

Reply With Quote
  #4 (permalink)  
Old July 28th, 2006, 06:01 PM
Authorized User
 
Join Date: Jul 2006
Location: , , Poland.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Of course it was my mistake.
I hope that this solution will be better and help You. In this case chart works like "button" which opens i.e Web site.
In new workbook (Sheet1) I made chart.
In VBA I inserted Class Module (its name KAZIK) and wrote this code:

Public WithEvents myChartClass As Chart
Option Explicit


Private Sub myChartClass_MouseDown()

ActiveWorkbook.FollowHyperlink Address:="http://www.google.pl/", NewWindow:=True

End Sub

Next I wrote code in This Workbook:

Dim SummaryChart As New KAZIK
Option Explicit

Private Sub Workbook_Open()
    Range("A1").Select
    Set SummaryChart.myChartClass = Worksheets(1).ChartObjects(1).Chart
End Sub



Kazik
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Chart Object In Access Report dorlesky Access VBA 0 July 26th, 2007 10:26 PM
object vs text hyperlink kritimehrotra Excel VBA 0 August 1st, 2006 08:40 PM
Using Excel Chart Object in VB App John Pennington Beginning VB 6 1 July 12th, 2006 01:39 PM
Using Customized chart for Pivot Chart kliu9 Excel VBA 3 October 13th, 2004 09:37 AM
Transfer of values from an object to an XY chart locusiste Excel VBA 0 April 23rd, 2004 05:02 PM



All times are GMT -4. The time now is 06:03 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.