PC Review


Reply
Thread Tools Rate Thread

Create Hyperlink in VBA

 
 
PPL
Guest
Posts: n/a
 
      17th Mar 2010
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





 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      18th Mar 2010
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
 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      18th Mar 2010
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
>
>
>
>
>
> .
>


 
Reply With Quote
 
PPL
Guest
Posts: n/a
 
      18th Mar 2010
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" <(E-Mail Removed)> wrote in message
news:2D58C537-D2BB-40D7-BE15-(E-Mail Removed)...
> 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
>>
>>
>>
>>
>>
>> .
>>

>



 
Reply With Quote
 
PPL
Guest
Posts: n/a
 
      18th Mar 2010
Thanks Dave,
Maybe I need to look at the FollowHyperlink method.
Thanks again for your response.

Phil

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      18th Mar 2010
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" <(E-Mail Removed)> wrote in message
> news:2D58C537-D2BB-40D7-BE15-(E-Mail Removed)...
> > 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
> >>
> >>
> >>
> >>
> >>
> >> .
> >>

> >

>
>
> .
>

 
Reply With Quote
 
PPL
Guest
Posts: n/a
 
      19th Mar 2010
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" <(E-Mail Removed)> wrote in message
news:NWdon.72971$(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Mar 2010
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" <(E-Mail Removed)> wrote in message
> news:NWdon.72971$(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I create a hyperlink =?Utf-8?B?RXJpayBIZW5kcmlja3Nvbg==?= Microsoft Outlook 8 25th Feb 2007 08:04 AM
How do I create a hyperlink to a cell with the hyperlink function =?Utf-8?B?Uy4gQmV2aW5z?= Microsoft Excel Worksheet Functions 2 20th Jul 2006 08:06 PM
Create Hyperlink =?Utf-8?B?bWFwZXJhbGlh?= Microsoft Excel Programming 2 10th Apr 2006 01:15 AM
Word: I create a hyperlink to a pdf. I ctrl-click on hyperlink, . =?Utf-8?B?QnJ1Y2U=?= Microsoft Word Document Management 0 18th Feb 2005 03:57 AM
can't create hyperlink to stephen Microsoft Powerpoint 2 8th Oct 2003 10:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:21 AM.