+ Reply to Thread
Results 1 to 7 of 7

macro button to insert rows - error message

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    uganda
    MS-Off Ver
    Excel 2010
    Posts
    8

    macro button to insert rows - error message

    Hi there,

    I'm using two macros (suggested by davesexcel in the thread "need to insert row with button", thanks) to create a button that when clicked, inserts a row... Here they are:

    Sub CreateButtonsInA_Selection()
    'this createts a button and assigns the InsertRow macro to it in a selection
    For Each Cell In Selection.Cells
    With ActiveSheet.Buttons
    .Add Cell.Left, Cell.Top, Cell.Width, Cell.Height
    .OnAction = "InsertRow"
    End With
    Next Cell
    End Sub

    Sub InsertRow()
    'this inserts a row where the button is clicked.
    Dim r As Range
    Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
    r.EntireRow.Insert
    End Sub

    However, when clicking the button, I get this error message: "Cannot run the macro "blablabla". The macro may not be available in this workbook or all macros may be disabled." Any ideas? Some additional info:
    - My file is a .xls, and I'm working in Excel 2010.
    - I've checked under "developer > code > macro security > macro settings" and both "Enable all macros (not recommended...)" and "Trust acces to the VBA project object model" are selected.
    - Under "developer > visual basic", when I select ThisWorkbook in the Project pane, I see the codes so the macros seem to be "in the file".

    Also, I have some additional questions:
    - Will the inserted row be above or below the row in which the button is? I want it to be above...
    - Will the inserted row contain the same formulas and have the same formatting (the cells containing the formulas should be locked) as the row in which the button is? If not, is there a way to get what Iwant?
    - I want the buttons to read "add row", is there a line I can add to the macro code so as to make this happen?

    Many thanks in advance!

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: macro button to insert rows - error message

    If the file .xls? in 2010 the files with macros are the type .xlsm

  3. #3
    Registered User
    Join Date
    01-15-2013
    Location
    uganda
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: macro button to insert rows - error message

    OK, I see.
    However, I have already tried saving as .xlsm and reopened then, but I encountered the same problem...

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: macro button to insert rows - error message

    when you opened the *.xlsm were you asked about permitting macros to be run (.... content?)

    better yet, upload an sensitive-data-empty file with the macros...

  5. #5
    Registered User
    Join Date
    01-15-2013
    Location
    uganda
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: macro button to insert rows - error message


  6. #6
    Registered User
    Join Date
    01-15-2013
    Location
    uganda
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: macro button to insert rows - error message

    any ideas?
    Last edited by seb_vdl; 01-17-2013 at 04:03 AM.

  7. #7
    Registered User
    Join Date
    01-15-2013
    Location
    uganda
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: macro button to insert rows - error message

    ah, i can apparently just attach the file straight to this reply... nice!
    so, any ideas about the issue? thanks!
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1