Easy question, I think

J

Judge Platt

I want to make a form button click a cell that has a hyperlink in it. Range
("B4").Select simply moves my cursor to that cell, but doesn't activate the
hyperlink. How do I activate the hyperlink?
 
R

Ron Coderre

If cell B4 actually contains a hyperlink
try something like this:

Sub GoToHyperlink()
[B4].Hyperlinks(1).Follow
End Sub

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)
 
J

Judge Platt

Thanks Ron. I think that's along the right track, except that the hyperlink
in B4 is created through the Excel formula HYPERLINK as opposed to attaching
a hyperlink. When I run that, I get: "Run-time error '9': subscript out of
range"

Ron Coderre said:
If cell B4 actually contains a hyperlink
try something like this:

Sub GoToHyperlink()
[B4].Hyperlinks(1).Follow
End Sub

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

Judge Platt said:
I want to make a form button click a cell that has a hyperlink in it.
Range
("B4").Select simply moves my cursor to that cell, but doesn't activate
the
hyperlink. How do I activate the hyperlink?
 
R

Ron Coderre

There may be another way....but, this is what I came up with:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub GoToHyperlinkFuncURL()
Dim strURL As String
Dim strSource As String

strSource = [B4].Formula

strURL = Range(Mid(Left(strSource, InStr(1, strSource, ",") - 1), _
InStr(1, strSource, "(") + 1))

ShellExecute _
hWnd:=0, _
lpOperation:=vbNullString, _
lpFile:=strURL, _
lpParameters:=vbNullString, _
lpDirectory:=vbNullString, _
nShowCmd:=5
End Sub

Is that something you can work with?

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)



Judge Platt said:
Thanks Ron. I think that's along the right track, except that the
hyperlink
in B4 is created through the Excel formula HYPERLINK as opposed to
attaching
a hyperlink. When I run that, I get: "Run-time error '9': subscript out
of
range"

Ron Coderre said:
If cell B4 actually contains a hyperlink
try something like this:

Sub GoToHyperlink()
[B4].Hyperlinks(1).Follow
End Sub

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

Judge Platt said:
I want to make a form button click a cell that has a hyperlink in it.
Range
("B4").Select simply moves my cursor to that cell, but doesn't activate
the
hyperlink. How do I activate the hyperlink?
 
R

Ron Coderre

I should mention....I assumed the HYPERLINK function referenced other cells
that contained the URL and the Dislayed Text.

If your formula actually contains the URL, the code can be shortened.

-------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

Ron Coderre said:
There may be another way....but, this is what I came up with:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub GoToHyperlinkFuncURL()
Dim strURL As String
Dim strSource As String

strSource = [B4].Formula

strURL = Range(Mid(Left(strSource, InStr(1, strSource, ",") - 1), _
InStr(1, strSource, "(") + 1))

ShellExecute _
hWnd:=0, _
lpOperation:=vbNullString, _
lpFile:=strURL, _
lpParameters:=vbNullString, _
lpDirectory:=vbNullString, _
nShowCmd:=5
End Sub

Is that something you can work with?

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)



Judge Platt said:
Thanks Ron. I think that's along the right track, except that the
hyperlink
in B4 is created through the Excel formula HYPERLINK as opposed to
attaching
a hyperlink. When I run that, I get: "Run-time error '9': subscript out
of
range"

Ron Coderre said:
If cell B4 actually contains a hyperlink
try something like this:

Sub GoToHyperlink()
[B4].Hyperlinks(1).Follow
End Sub

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

I want to make a form button click a cell that has a hyperlink in it.
Range
("B4").Select simply moves my cursor to that cell, but doesn't
activate
the
hyperlink. How do I activate the hyperlink?
 
J

Judge Platt

Yes. Thanks, Ron.

Ron Coderre said:
There may be another way....but, this is what I came up with:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub GoToHyperlinkFuncURL()
Dim strURL As String
Dim strSource As String

strSource = [B4].Formula

strURL = Range(Mid(Left(strSource, InStr(1, strSource, ",") - 1), _
InStr(1, strSource, "(") + 1))

ShellExecute _
hWnd:=0, _
lpOperation:=vbNullString, _
lpFile:=strURL, _
lpParameters:=vbNullString, _
lpDirectory:=vbNullString, _
nShowCmd:=5
End Sub

Is that something you can work with?

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)



Judge Platt said:
Thanks Ron. I think that's along the right track, except that the
hyperlink
in B4 is created through the Excel formula HYPERLINK as opposed to
attaching
a hyperlink. When I run that, I get: "Run-time error '9': subscript out
of
range"

Ron Coderre said:
If cell B4 actually contains a hyperlink
try something like this:

Sub GoToHyperlink()
[B4].Hyperlinks(1).Follow
End Sub

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

I want to make a form button click a cell that has a hyperlink in it.
Range
("B4").Select simply moves my cursor to that cell, but doesn't activate
the
hyperlink. How do I activate the hyperlink?
 
H

hupjack

Hi Ron,

I found this post while searching for some Excel VBA help for some tools I'm
making to improve a few processes at my work, and it comes really close to
answering my question.

I've taken a basic C programming course back 5 years ago as part of my
mechanical engineering degree and I know basic HTML. So I'm basically a
programming novice hacking my way through some VBA in excel.

I took a couple screen captures so you can see what I'm trying to accomplish

http://vbahelptwo032308.notlong.com
http://vbahelp032308.notlong.com

As you can see, I've put some URLs sitting way out there at column BI in
this spreadsheet I've made.

In cell BI14, I've got a URL formed from the following excel command
="https://na1.salesforce.com/search/SearchResults?searchType=1&sbstr="&CUSTOMER_NAME

If my customer name was "demo" the results showing up in that cell are
https://na1.salesforce.com/search/SearchResults?searchType=1&sbstr=demo
which is precisely the URL needed to perform a salesforce search on that
fake customer name.

your first suggestion to the original poster almost worked for me.
Private Sub CommandButton1_Click()
[BI14].Hyperlinks(1).Follow
End Sub

Perhaps this wasn't the right way to "implement it", but I just stuck the
Hyperlinks(1).Follow command, in as the action for the CommandButton1_Click
code that automatically got placed when I created the button.

The result when the button was clicked.... the "customer name" defined in
my excel spreadsheet at Cell B3 doesn't get passed with the URL, so it just
launches a web browser with the first part of the URL and without a search
term https://na1.salesforce.com/search/SearchResults?searchType=1&sbstr=

So... How do I pass the *output* from my formula at BI14 that tacks the
customer name on the end of that URL, so that when I click a button, it
launches a web browser with that full URL with the search term?

I think I need a little more VBA hand holding to implement your second
suggestion. I wasn't sure where to declare that function. Should I create a
new "module" with your quoted code? and then where / what do I reference
with the button I create? Previously I made a button that invoked a certain
macro I had written, but in design mode, after creating a new button, I don't
even see in its properties how to point to a specific macro. There must be
different ways to create different types of buttons.

An excel VBA for dummies book might be in my future.
http://www.j-walk.com/ss/ any recommendations? Excel 2003 power programming
with VBA? or the dummies book, or a different one completely?

If anybody wants extra credit, I've got another (likely very simple) VBA
question regarding this same tool I'm working on over here.
http://community.salesforce.com/sforce/board/message?board.id=Excel_Connector&message.id=806#M806

Thanks in advance for any help anybody can offer!
-Ethan (in San Diego)


Ron Coderre said:
There may be another way....but, this is what I came up with:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub GoToHyperlinkFuncURL()
Dim strURL As String
Dim strSource As String

strSource = [B4].Formula

strURL = Range(Mid(Left(strSource, InStr(1, strSource, ",") - 1), _
InStr(1, strSource, "(") + 1))

ShellExecute _
hWnd:=0, _
lpOperation:=vbNullString, _
lpFile:=strURL, _
lpParameters:=vbNullString, _
lpDirectory:=vbNullString, _
nShowCmd:=5
End Sub

Is that something you can work with?

--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)



Judge Platt said:
Thanks Ron. I think that's along the right track, except that the
hyperlink
in B4 is created through the Excel formula HYPERLINK as opposed to
attaching
a hyperlink. When I run that, I get: "Run-time error '9': subscript out
of
range"

Ron Coderre said:
If cell B4 actually contains a hyperlink
try something like this:

Sub GoToHyperlink()
[B4].Hyperlinks(1).Follow
End Sub

Is that something you can work with?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

I want to make a form button click a cell that has a hyperlink in it.
Range
("B4").Select simply moves my cursor to that cell, but doesn't activate
the
hyperlink. How do I activate the hyperlink?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top