Excel macros and hperlinks

Posted on 2006-05-09
Last Modified: 2008-02-01
im building something in excel and i need some help
ive made a simple macro to insert a new row

Sub AddRow()
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
Question by:HOW
    LVL 35

    Accepted Solution

    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
    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")


    Assisted Solution

    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.
    LVL 2

    Author Comment

    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://*****.***

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now