Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default using VBA in the function bar

I am working on a workbook which has the VBA editor lock by a password.
so I can't write or see VBA code.
but what I would like to do is being able to write some quick VBA in
the function bar.

Imagine in E5 a cell with text and an Hyperlink, in F5 an empty cell.
in F5, I would like to put something like


=Range('E5').Hyperlinks(1).Address

and then being able to see the Hyperlink of E5 in the F5 cell.

but I can't get a Range object in the cell itself.

is it possible? how?
please help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default using VBA in the function bar

Roedd wedi ysgrifennu:

I am working on a workbook which has the VBA editor lock by a
password. so I can't write or see VBA code.
but what I would like to do is being able to write some quick VBA in
the function bar.

Imagine in E5 a cell with text and an Hyperlink, in F5 an empty cell.
in F5, I would like to put something like


=Range('E5').Hyperlinks(1).Address

and then being able to see the Hyperlink of E5 in the F5 cell.

but I can't get a Range object in the cell itself.

is it possible? how?


I was intrigued by this idea. Not sure how useful it is, but here goes.

Get hold of the Microsoft Script Control. It should still be available from
a dark and dusty corner of MSDN.

Drop a script control onto a sheet in your workbook. I used Sheet1 and kept
the default name for the instance of the script control.

Then, add the following code to a standard module in your workbook:

Public Function VisualBasic(Code As String) As Variant

Dim scrExecute As ScriptControl

On Error GoTo ERR_LOC

With Sheet1.ScriptControl1
.Reset
.Language = "VBScript"
.Timeout = "10000"
.AddObject "Application", ThisWorkbook.Application, True
.AddCode "Function EvalMe()" & vbLf & "EvalMe = " & Code _
& vbLf & "End Function"
VisualBasic = .Run("EvalMe")
End With

Exit Function

ERR_LOC:

VisualBasic = Sheet1.ScriptControl1.Error.Description

End Function

Using this, I was able to run very simple VB code inside a worksheet
function such as:
=visualbasic("cells(2).value")
=visualbasic("cells(3).offset(2,1).value")
and
=visualbasic("cells(5,5).Hyperlinks(1).Address")

Note that you can't use embedded quote characters as the code stands, but
I'm sure you could work around that easily.

HTH

--
Rob



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default using VBA in the function bar

thanks for the info. but I dont have access to the VBA editor on this
spreadsheet. so I cannot paste anycode but just use what is given by
default.

in other terms, according to what you said, if I need to create extra
code to enable this function, it means its not available by default. a
bit sad, but I understand. everything can not be there ...

so I found a work around, I'm gonna use ruby instead of vba and access
the sheet remotly, much more powerful anyway.

regards

Robert Bruce wrote:
Roedd wedi ysgrifennu:

I am working on a workbook which has the VBA editor lock by a
password. so I can't write or see VBA code.
but what I would like to do is being able to write some quick VBA in
the function bar.

Imagine in E5 a cell with text and an Hyperlink, in F5 an empty cell.
in F5, I would like to put something like


=Range('E5').Hyperlinks(1).Address

and then being able to see the Hyperlink of E5 in the F5 cell.

but I can't get a Range object in the cell itself.

is it possible? how?


I was intrigued by this idea. Not sure how useful it is, but here goes.

Get hold of the Microsoft Script Control. It should still be available from
a dark and dusty corner of MSDN.

Drop a script control onto a sheet in your workbook. I used Sheet1 and kept
the default name for the instance of the script control.

Then, add the following code to a standard module in your workbook:

Public Function VisualBasic(Code As String) As Variant

Dim scrExecute As ScriptControl

On Error GoTo ERR_LOC

With Sheet1.ScriptControl1
.Reset
.Language = "VBScript"
.Timeout = "10000"
.AddObject "Application", ThisWorkbook.Application, True
.AddCode "Function EvalMe()" & vbLf & "EvalMe = " & Code _
& vbLf & "End Function"
VisualBasic = .Run("EvalMe")
End With

Exit Function

ERR_LOC:

VisualBasic = Sheet1.ScriptControl1.Error.Description

End Function

Using this, I was able to run very simple VB code inside a worksheet
function such as:
=visualbasic("cells(2).value")
=visualbasic("cells(3).offset(2,1).value")
and
=visualbasic("cells(5,5).Hyperlinks(1).Address")

Note that you can't use embedded quote characters as the code stands, but
I'm sure you could work around that easily.

HTH

--
Rob


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
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM


All times are GMT +1. The time now is 04:57 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"