• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

Excel macros and hperlinks

hey
im building something in excel and i need some help
ive made a simple macro to insert a new row

Sub AddRow()
ActiveCell.EntireRow.Insert
End Sub

i want to put a button on page that when u click it inserts a row above the button but i tried it and when you click the button the cell doesnt receive foucus so it inserts it at the last active cell.i want the button to be in the cell not sitting on top of it? any suggestions

also i have a hyperlink that updates a php file with some values but i dont want the page to open i just want it to run the php file.any suggestions anyone?
thanks for reading this
0
HOW
Asked:
HOW
2 Solutions
 
mvidasCommented:
Hi HOW,

Buttons have a property called .TopLeftCell, which returns a range reference to the cell the top-left corner of the button is in.
You could try changing the procedure to a function, with an optional argument for cell to insert from:

Function AddRow(Optional ByVal TheCell As Range)
 If TheCell Is Nothing Then Set TheCell = ActiveCell
 TheCell.EntireRow.Insert
End Function

When that is run by itself, it will insert it at the activecell like you currently have. But if you call it from a button, like:

Private Sub CommandButton1_Click()
 AddRow CommandButton1.TopLeftCell
End Sub

Then it uses that cell.  You could also specify the cell directly if you wanted, like:
 AddRow Range("A7")

Matt
0
 
rajanishshuklaCommented:
Buttons have a property called TakeFocusOnClick which can be set to False. Once this property is set to false the click will recognise activecell and the rest of your code will work fine.
0
 
HOWAuthor Commented:
thanks guys that worked fine
what about the other bit

>>also i have a hyperlink that updates a php file with some values but i dont want the page to open i just want it to run the php file.any suggestions anyone?

or how can i get a vbscript to read a text or php file thats on the web ive tried using open but it says path not found when i use http://*****.***
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now