Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gil Gil is offline
external usenet poster
 
Posts: 14
Default Getting coordinates of an Hyperlink using range get_Top(), get_Lef

I created an automation project using MFC and created classes from the Excel
2003 type library. I am trying to get the coordinates of a hyperlink in the
worksheet by using the range get_Top(), get_Left(), get_Width() and
get_Height() methods of the range class. I always get a value of 0 returned.
I have included some code below. Any ideas why the values for the top, left,
width and height are always 0?
A VBA macro using the same Top, Left, etc does return the coordinates.

Thanks for any help that you can provide,

Gil

for (int idx = 1; idx <= numSheets; idx++)
{
CComVariant vIntSheet;
vIntSheet.llVal = idx;
vIntSheet.vt = VT_I4;


// Get Hyperlinks
sheet = sheets.get_Item(vIntSheet);
hyperLinks = sheet.get_Hyperlinks();

long iNumHyperLinks = hyperLinks.get_Count();

msg.Format("Sheet %d - Number of HyperLinks = %d\n", idx,
iNumHyperLinks);

// For number of hyperlinks on the Worksheet
for (int iLink = 1; iLink <= iNumHyperLinks; iLink++)
{
CComVariant vIntHyperlink;

vIntHyperlink.lVal = iLink;
vIntHyperlink.vt = VT_I4;

hyperlink = hyperLinks.get_Item(vIntHyperlink);

CComBSTR bstrName;
CComBSTR bstrAddress;

CString Name;
CString Address;
CString SubAddress;

Name = hyperlink.get_Name();
bstrName = Name.AllocSysString();

Address = hyperlink.get_Address();
bstrAddress = Address.AllocSysString();

SubAddress = hyperlink.get_SubAddress();


int pageNum = vIntSheet.lVal;

msg.Format("Sheet Number: %d\n", pageNum);
OutputDebugString(msg);
msg.Format("Hyperlink Name: %s\nHyperlink Address: %s\n",
Name, Address);
OutputDebugString(msg);
msg.Format("Hyperlink SubAddress: %s\n", SubAddress);
OutputDebugString(msg);

range = hyperlink.get_Range();

CComVariant vRangeInfoTop;
vRangeInfoTop = range.get_Top();

msg.Format("Hyperlink Range - Top: %10.5lf\n",
vRangeInfoTop.fltVal);
OutputDebugString(msg);
CComVariant vRangeInfoLeft;
vRangeInfoLeft = range.get_Left();

msg.Format("Hyperlink Range - Left: %s\n", (LPCSTR)
vRangeInfoLeft.bstrVal);
OutputDebugString(msg);
CComVariant vRangeInfoWidth;
vRangeInfoWidth = range.get_Width();

CComVariant vRangeInfoHeight;
vRangeInfoHeight = range.get_Height();

font = range.get_Font();

CComVariant vIntFontSize;
vIntFontSize = font.get_Size();

double fontSizePts = vIntFontSize.fltVal;

rect_xlow = (double) vRangeInfoLeft.fltVal;
rect_ylow = (double) vRangeInfoTop.fltVal;
rect_xhi = rect_xlow + (double) vRangeInfoWidth.fltVal;
rect_yhi = rect_ylow + (double) vRangeInfoHeight.fltVal;
}
}

  #2   Report Post  
Posted to microsoft.public.excel.programming
Gil Gil is offline
external usenet poster
 
Posts: 14
Default Getting coordinates of an Hyperlink using range get_Top(), get_Lef

Problem solved...

"Gil" wrote:

I created an automation project using MFC and created classes from the Excel
2003 type library. I am trying to get the coordinates of a hyperlink in the
worksheet by using the range get_Top(), get_Left(), get_Width() and
get_Height() methods of the range class. I always get a value of 0 returned.
I have included some code below. Any ideas why the values for the top, left,
width and height are always 0?
A VBA macro using the same Top, Left, etc does return the coordinates.

Thanks for any help that you can provide,

Gil

for (int idx = 1; idx <= numSheets; idx++)
{
CComVariant vIntSheet;
vIntSheet.llVal = idx;
vIntSheet.vt = VT_I4;


// Get Hyperlinks
sheet = sheets.get_Item(vIntSheet);
hyperLinks = sheet.get_Hyperlinks();

long iNumHyperLinks = hyperLinks.get_Count();

msg.Format("Sheet %d - Number of HyperLinks = %d\n", idx,
iNumHyperLinks);

// For number of hyperlinks on the Worksheet
for (int iLink = 1; iLink <= iNumHyperLinks; iLink++)
{
CComVariant vIntHyperlink;

vIntHyperlink.lVal = iLink;
vIntHyperlink.vt = VT_I4;

hyperlink = hyperLinks.get_Item(vIntHyperlink);

CComBSTR bstrName;
CComBSTR bstrAddress;

CString Name;
CString Address;
CString SubAddress;

Name = hyperlink.get_Name();
bstrName = Name.AllocSysString();

Address = hyperlink.get_Address();
bstrAddress = Address.AllocSysString();

SubAddress = hyperlink.get_SubAddress();


int pageNum = vIntSheet.lVal;

msg.Format("Sheet Number: %d\n", pageNum);
OutputDebugString(msg);
msg.Format("Hyperlink Name: %s\nHyperlink Address: %s\n",
Name, Address);
OutputDebugString(msg);
msg.Format("Hyperlink SubAddress: %s\n", SubAddress);
OutputDebugString(msg);

range = hyperlink.get_Range();

CComVariant vRangeInfoTop;
vRangeInfoTop = range.get_Top();

msg.Format("Hyperlink Range - Top: %10.5lf\n",
vRangeInfoTop.fltVal);
OutputDebugString(msg);
CComVariant vRangeInfoLeft;
vRangeInfoLeft = range.get_Left();

msg.Format("Hyperlink Range - Left: %s\n", (LPCSTR)
vRangeInfoLeft.bstrVal);
OutputDebugString(msg);
CComVariant vRangeInfoWidth;
vRangeInfoWidth = range.get_Width();

CComVariant vRangeInfoHeight;
vRangeInfoHeight = range.get_Height();

font = range.get_Font();

CComVariant vIntFontSize;
vIntFontSize = font.get_Size();

double fontSizePts = vIntFontSize.fltVal;

rect_xlow = (double) vRangeInfoLeft.fltVal;
rect_ylow = (double) vRangeInfoTop.fltVal;
rect_xhi = rect_xlow + (double) vRangeInfoWidth.fltVal;
rect_yhi = rect_ylow + (double) vRangeInfoHeight.fltVal;
}
}

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
get range coordinates zz Excel Programming 1 October 27th 06 07:08 PM
And once again: X and Y Screen Coordinates of a Range marsou Excel Programming 8 August 23rd 05 11:43 AM
Simple way to convert UTM ED50 coordinates to decimal coordinates? Dan[_38_] Excel Programming 8 July 11th 04 04:54 PM
getting coordinates of a range Kent Eilers Excel Programming 5 February 13th 04 02:09 PM
Converting MouseDown Coordinates to Chart Point Coordinates Steve[_50_] Excel Programming 3 December 2nd 03 06:48 PM


All times are GMT +1. The time now is 01:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"