Replace or override sub code

Annichka

New Member
Joined
Jun 24, 2019
Messages
5
Hi! so I'm very new with Vba in excel. i have a code that sends specific data (from excel files) to an access database. i wrote a code that loops through several hundred files and sends this information. The problem is to manually update these files, it is sent with a button. I need to override the current sub:

Public Sub Send_Record_Click()
MsgBox ("Not Functional at present")
End Sub

with a code that connects to another sub in Module 1.
Originally i was thinking to just replace the module with the Send_Record_Click() with an identical one that has the right updated version, but this is a code on a sheet with a several other codes and not a module.
Another idea was to run a If Then Sub that would look at this sub and if it had this msgbox code it would replace it with the call SendToAccess sub I have in Module 1.
Any other ideas and code samples are very much welcome if this is even possible to do.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Welcome to the Board!

Your question seems a bit confusing to me, but I am thinking you can break these different options out into their own Subs, and then based on some decision in your main sub, decide which one to call, i.e.
Code:
If [COLOR=#0000ff][I]some condition[/I][/COLOR] then
    Call Sub1
Else
    Call Sub2
End If
If that doesn't help you out, we are going to need more clarification/details of your situation.
 
Last edited:
Upvote 0
thank you! ok so thats not quite what i needed. The code im writing loops through about 700 files and sends specific cells in an excel workbook into a database. Unfortunately to manually send it you double click a button that goes to that Sub Send_Record_Click(). but because these files were created before the database, the double click just pops up with the msgbox. I need some help in order to write a sub that will help automatically change the Send_Record_Click() sub from a msg box to a call module.
 
Upvote 0
but this is a code on a sheet with a several other codes and not a module

Is the code worksheet event code or a regular sub?
 
Upvote 0
Without seeing all the code involved and working through an actual example, I find it very confusing and am not very clear on exactly how you expect this to work.
This line of note is confusing:
Unfortunately to manually send it you double click a button that goes to that Sub Send_Record_Click(). but because these files were created before the database, the double click just pops up with the msgbox. I need some help in order to write a sub that will help automatically change the Send_Record_Click() sub from a msg box to a call module.
What do you mean that the "files were created before the database"? Where, why, how is the database being created?
What exactly is the determinging the decision on what to do? Do you want to check for the existence of the database first?
 
Upvote 0
i so had to re-read this to finally understand the question.

I think your issue is, some of the workbooks were created first (and they have the "not functional" message in them). Later, you changed the process and added a code module into it that had a function call in it to do what you needed.

So, first, I don't think you can do it the way you are proposing.

You need to re-write your controlling process (that loops through the list of 700 files) so that it doesn't need to make calls into code modules inside each of the 700 workbooks. Instead, have the source loop/control code do it. That's without seeing exactly what you're doing but very generally if you're just opening a file then grabbing values from a specific worksheet/cell location, you can automate that centrally.
 
Upvote 0
mdmilner,
okay thank you so much! that was basically the issue. So thats what i was coming to the conclusion of. I dont think its possible to do what i was trying to.
Thank you again for your help!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top