Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PPL PPL is offline
external usenet poster
 
Posts: 18
Default Create Hyperlink in VBA

Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens in a
new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined error

Anyone any idea where am I going wrong ???

TIA





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Create Hyperlink in VBA

When I look at VBA's help for the Add method for Hyperlinks, I see this:

Add method as it applies to the Hyperlinks object.

Adds a hyperlink to the specified range or shape. Returns a Hyperlink object.

expression.Add(Anchor, Address, SubAddress, ScreenTip, TextToDisplay)
expression Required. An expression that returns a Hyperlinks object.

Anchor Required Object. The anchor for the hyperlink. Can be either a Range
or Shape object.

Address Required String. The address of the hyperlink.

SubAddress Optional Variant. The subaddress of the hyperlink.

ScreenTip Optional Variant. The screen tip to be displayed when the mouse
pointer is paused over the hyperlink.

TextToDisplay Optional Variant. The text to be displayed for the hyperlink.


======
I don't see NewWindow or addhistory parms.

I think you've gotten these parms confused with .FollowHyperlink's parms.



PPL wrote:

Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens in a
new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined error

Anyone any idea where am I going wrong ???

TIA


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Create Hyperlink in VBA

Try....

Sub Test2()

ActiveSheet.Range("A19").Select
With ActiveSheet
.Hyperlinks.Add Anchor:=Selection, Address:= _
"c:\1\test.htm", TextToDisplay:="Test"
End With
End Sub

"PPL" wrote:

Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens in a
new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined error

Anyone any idea where am I going wrong ???

TIA





.


  #4   Report Post  
Posted to microsoft.public.excel.programming
PPL PPL is offline
external usenet poster
 
Posts: 18
Default Create Hyperlink in VBA

Thanks Brian,
That works well. However I need the file to open in a new window.

I've tried appending NewWindow:=True to your Hyperlinks.Add method as
follows:

ActiveSheet.Range("A19").Select
With ActiveSheet
.Hyperlinks.Add Anchor:=Selection, Address:= _
"c:\1\test.htm", TextToDisplay:="Test", NewWindow:="True"
End With
End Sub


I'm getting Runtime Error 1004: Application defined or Object defined error.

Is there any other way of achieving the same result please?

Thanks again
Phil


"Brian" wrote in message
...
Try....

Sub Test2()

ActiveSheet.Range("A19").Select
With ActiveSheet
.Hyperlinks.Add Anchor:=Selection, Address:= _
"c:\1\test.htm", TextToDisplay:="Test"
End With
End Sub

"PPL" wrote:

Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens
in a
new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined
error

Anyone any idea where am I going wrong ???

TIA





.




  #5   Report Post  
Posted to microsoft.public.excel.programming
PPL PPL is offline
external usenet poster
 
Posts: 18
Default Create Hyperlink in VBA

Thanks Dave,
Maybe I need to look at the FollowHyperlink method.
Thanks again for your response.

Phil

"Dave Peterson" wrote in message
...
When I look at VBA's help for the Add method for Hyperlinks, I see this:

Add method as it applies to the Hyperlinks object.

Adds a hyperlink to the specified range or shape. Returns a Hyperlink
object.

expression.Add(Anchor, Address, SubAddress, ScreenTip, TextToDisplay)
expression Required. An expression that returns a Hyperlinks object.

Anchor Required Object. The anchor for the hyperlink. Can be either a
Range
or Shape object.

Address Required String. The address of the hyperlink.

SubAddress Optional Variant. The subaddress of the hyperlink.

ScreenTip Optional Variant. The screen tip to be displayed when the
mouse
pointer is paused over the hyperlink.

TextToDisplay Optional Variant. The text to be displayed for the
hyperlink.


======
I don't see NewWindow or addhistory parms.

I think you've gotten these parms confused with .FollowHyperlink's parms.



PPL wrote:

Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens
in a
new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined
error

Anyone any idea where am I going wrong ???

TIA


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Create Hyperlink in VBA

To be honest I am not sure why it would not open it in a new window. It does
for me, I wonder if that is just something to do with the brower where it is
set to automatically open new windows as a new tab if a window is already
open? As I said, mine opens fine so I do not think it is a excel issue.

Also, as far as I know newwindow is not a valid variable for the hyperlinks
function.

"PPL" wrote:

Thanks Brian,
That works well. However I need the file to open in a new window.

I've tried appending NewWindow:=True to your Hyperlinks.Add method as
follows:

ActiveSheet.Range("A19").Select
With ActiveSheet
.Hyperlinks.Add Anchor:=Selection, Address:= _
"c:\1\test.htm", TextToDisplay:="Test", NewWindow:="True"
End With
End Sub


I'm getting Runtime Error 1004: Application defined or Object defined error.

Is there any other way of achieving the same result please?

Thanks again
Phil


"Brian" wrote in message
...
Try....

Sub Test2()

ActiveSheet.Range("A19").Select
With ActiveSheet
.Hyperlinks.Add Anchor:=Selection, Address:= _
"c:\1\test.htm", TextToDisplay:="Test"
End With
End Sub

"PPL" wrote:

Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens
in a
new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined
error

Anyone any idea where am I going wrong ???

TIA





.




.

  #7   Report Post  
Posted to microsoft.public.excel.programming
PPL PPL is offline
external usenet poster
 
Posts: 18
Default Work-around to Create Hyperlink in VBA

Thank you to those who replied.
I've found a work-around to the problem of not being able to configure a
hyperlink in Excel to open in a new browser window. Essentially I used an
excel rectangular autoshape drawing object. placed it over the cell that
requires the hyperlink.
Formatted the rectangle w/ white border & no fill (i.e. Transparent)
Removed the hyperlink in the cell & formatted the text in blue w/ underline
Right click the rectangle autoshape Assign Macro

Sub MyHyperlinkInNewWindow
Dim KB_ArticlePath As String
KB_ArticlePath = "http:/anarticle.htm"
ThisWorkbook.FollowHyperlink Address:=KB_ArticlePath, NewWindow:=True
End sub

That's it. It works like a charm.
Not fun for anyone else who wants to change the link because a casual look
at it and you'd never know that it's anything else than ... well .. a
hyperlink!

Phil





"PPL" wrote in message
...
Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens in
a new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined
error

Anyone any idea where am I going wrong ???

TIA







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Work-around to Create Hyperlink in VBA

You could plop a button from the Forms toolbar in row 1 of your worksheet.

Then freeze the window (Window|Freeze Panes (in xl2003 menus) so that row 1 is
always visible.

Then assign your macro to the button.

But change the macro slightly.

Option Explicit
Sub MyHyperlinkInNewWindow()
With ActiveCell
If .Hyperlinks.Count 0 Then
ThisWorkbook.FollowHyperlink _
Address:="http://" & .Value, _
NewWindow:=True
End If
End With
End Sub


This will only run if the user selects the cell and clicks on the button--not if
the user clicks on the hyperlink itself.

You could remove the hyperlink and use some other indicator (value starts with
an HTTP://???).

Option Explicit
Sub MyHyperlinkInNewWindow()
With ActiveCell
If UCase(Left(.Value, 7)) = UCase("http://") Then
ThisWorkbook.FollowHyperlink _
Address:=.Value, _
NewWindow:=True
End If
End With
End Sub

(notice that the "http://" was dropped in the second suggestion, while the first
suggestion added it to the hyperlink address.)

PPL wrote:

Thank you to those who replied.
I've found a work-around to the problem of not being able to configure a
hyperlink in Excel to open in a new browser window. Essentially I used an
excel rectangular autoshape drawing object. placed it over the cell that
requires the hyperlink.
Formatted the rectangle w/ white border & no fill (i.e. Transparent)
Removed the hyperlink in the cell & formatted the text in blue w/ underline
Right click the rectangle autoshape Assign Macro

Sub MyHyperlinkInNewWindow
Dim KB_ArticlePath As String
KB_ArticlePath = "http:/anarticle.htm"
ThisWorkbook.FollowHyperlink Address:=KB_ArticlePath, NewWindow:=True
End sub

That's it. It works like a charm.
Not fun for anyone else who wants to change the link because a casual look
at it and you'd never know that it's anything else than ... well .. a
hyperlink!

Phil

"PPL" wrote in message
...
Excel 2002 / 2003.
I'm trying to create a hyperlink in cell A19 such that the result opens in
a new window. I'm using

Range("A19").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\test.htm",
NewWindow:=True, AddHistory:=True

I'm getting Runtime Error 1004: Application defined or Object defined
error

Anyone any idea where am I going wrong ???

TIA






--

Dave Peterson
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
Need to create an automatic hyperlink [email protected] Excel Discussion (Misc queries) 3 April 1st 10 03:39 PM
Create Hyperlink to URL Filips Benoit[_2_] Excel Programming 4 November 13th 09 07:26 AM
How do I create a hyperlink to a cell with the hyperlink function S. Bevins Excel Worksheet Functions 2 July 20th 06 08:06 PM
Create Hyperlink maperalia Excel Programming 2 April 10th 06 01:15 AM
Create a HYPERLINK with a macro? bobgerman[_3_] Excel Programming 2 December 22nd 03 06:41 PM


All times are GMT +1. The time now is 04:13 AM.

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

About Us

"It's about Microsoft Excel"