+ Reply to Thread
Results 1 to 2 of 2

Trouble Calling Macro within Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2016
    Location
    New Hampshire
    MS-Off Ver
    Excel 2010
    Posts
    1

    Trouble Calling Macro within Macro

    I am trying to write a macro that calls another macro, but am running into difficulties. My company has a macro that imports data. The macro has a button that requires that you type or paste in a certain code that uniquely IDs a data series, then click import data, then wa la the vba code does all the hard work of pasting in the data for you.

    I am trying to write a second macro that loops through the universe of unique codes and automatically runs this import one time for each code and saves a separate file for each code so I don't even have to type in all the codes myself and wait for vba to run before my data appears. The problem is when I try and record the 2nd looping macro, I (1) run the old macro and (2) paste in the code, but VBA doesn't seem to recognize the macro button as a place (like a cell) so it is not capturing that I am pasting in the code into the macro button interface. Help! Is there a way around this? Thank you very much.

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
    Sheets("list of unique codes").Select [here is where I'm selecting the unique code]
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "code1" [the unique code is code1]
    Sheets("Screen").Select
    Application.Run "'Import Data Template.xlsm'!Sheet01.ImportButton_Click" [this is the old macro, but it's not recognizing that I'm actually pasting in the text string 'code1' into the macro button interface]
    End Sub [ultimately I plan to make this subroutine a loop]

  2. #2
    Forum Contributor
    Join Date
    09-23-2007
    Location
    Melbourne, Australia
    Posts
    176

    Re: Trouble Calling Macro within Macro

    Hi there.. I'm trying to understand your question.

    I am trying to write a second macro that loops through the universe of unique codes and automatically runs this import one time for each code and saves a separate file for each code so I don't even have to type in all the codes myself and wait for vba to run before my data appears.
    That part makes sense.
    The problem is when I try and record the 2nd looping macro, I (1) run the old macro and (2) paste in the code, but VBA doesn't seem to recognize the macro button as a place (like a cell) so it is not capturing that I am pasting in the code into the macro button interface.
    The above bolded part is what I don't understand?

    So from what I can gather, you have an interface with a button in that interface. You are displaying aform to do this.


    -Then you enter a unique code into that form (into a text box or something like that).. From here do you press a button and the macro should run?


    -The last part seems to contradict what you have said originally.... That is...you are looping through the entire universe of codes and importing data for each code OR... Are you entering a code into an interface and letting the macro find the code for that unique code > then importing the data?

    It's important to try to get these facts right so we can help you as the second part of your question is a little confusing.


    I think the problem is.. on a third read of this.. is that you are trying to use the macro recorder to do this. I can't see this working. Could you attach a small example of the data sheets you are using?


    Thanks..
    Last edited by danny2000; 03-01-2016 at 11:27 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  2. [SOLVED] Trouble automatically calling macro when cell value changes
    By cdutton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2014, 09:00 PM
  3. Calling macro 10 times, add header list to macro call only once
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2013, 09:42 AM
  4. [SOLVED] Calling a macro from an event macro. Using nest loops with if statements
    By c0d3crunch3r in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-12-2012, 08:31 AM
  5. Button command doesnt work while calling a macro from a macro
    By bryan444 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 09:39 AM
  6. From a macro, Calling anoter macro at a given line
    By aca in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-13-2007, 06:39 PM
  7. Trouble calling macro
    By James W. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2005, 03:06 PM

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