VBA to perform 'click' function

R2ah1ze1l

Board Regular
Joined
Nov 10, 2017
Messages
94
Good day all,

Struggling with this 'click' functionality. I have seen some instances where vba can be used to call a click function to occur. I am currently struggling with it. Mimicing lines of code is not working and I am curious if this is due to a naming issue, or that I have too much else taking place with the other vba routine that there is generated conflict.

I am recieving a Run-time error '424':
Object required

This occurs when the searched for information is not appearing in the requested file. It is hung up when trying to close the document. Here is the code:

Code:
  If ia > 16382 Then
   MsgBox "SN was not found in the document(s), ensure the SN and Issue# match output file(s)."
   Application.ScreenUpdating = True
   Range("A3").Select
   SRC_Workbook.Save 'need to store when import_click functionality is present
   SCR_Workbook.Close
    GoTo Leave
  End If

Here is the code that looks like it should perform the click function but clearly is not:

Code:
Worksheets("DATA").Select
Worksheets("DATA").Activate
ActiveWorkbook.Sheets("Data").Import.Value = True ' Import_Click from Tabulated Data sheets

I have tried everything I can think of to get this switch to function correctly. I can import data from the original file with other instances of Excel open. I can also have 1 instance and other workbooks open. So that doesn't seem to be my hardship, I'm hoping someone may have another idea. FYI the buttons name is 'Import' and in the same case as referenced. Is 'Import' and illegal term to use for a button name?
 
Your use of the term 'click' may be confusing people. A button is only a means to run a macro. I think it would be good if you could better explain what you need help for. From your explaination so far, all I can tell is that you have one workbook that has a macro written by somebody else that does something you like. Now you have another workbook and you want to write another macro that does something else similar to the first macro, but not exactly the same.

Perhaps the place to start would be for you to post the code of the vba macro you already have.

attachment.php

Thank you for the input rlv01, should Norie's advice not suit what I am doing, I will definitely post my *new* code.
Even if it does, I will add the finish result so others could possibly benefit!
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code:
Set SRC_Workbook = Workbooks.Open(path_fld)
Application.ScreenUpdating = True 'False for production use, True for Testing
Worksheets("DATA").Select
Worksheets("DATA").Activate
'ActiveWorkbook.Sheets("Data").Import.Value = True ' Import_Click from Tabulated Data sheets
'Call Import_Click
Application.Run (Import)

So all 3 of the options, with variations have been tried. None of these are getting the file to update.
Option 1 and 3 will allow the information to process until the document that does not have the SN is opened. Then I get a warning that I built into the code for when the SN isn't found.
Option 2 errors on me and does not make it even as far as checking the file for a matching SN. As a matter of fact, this one doesn't even make it to the 2nd of the 3 files I have being checked

Now may be a good time to note, the button name in the original file is 'Import' the macro is 'Import_Click', in all instances I have tried both variations to no avail.

FWIW,
This code performs the find/copy/save as desired in its original state. I am trying to finish off what I need for the automation to prevent the need of additional support on weekends/nights.
 
Upvote 0
If you are using Application.Run you need to include the name of the workbook that the code you want to run is in.
 
Upvote 0
... and the name of the macro.... is it "Import" or "Import_Click"?

Is the macro in a code module or in a sheet module?
Is the macro declared "Public" or "Private"?
 
Upvote 0
... and the name of the macro.... is it "Import" or "Import_Click"?

Is the macro in a code module or in a sheet module?
Is the macro declared "Public" or "Private"?

Private Sub Import_Click()
If you view the properties of the button, the buttons name is Import

I have been able to select and execute a private button from another workbook, it was just not performing such a large function.

I find the code for Import_Click on Sheet1 of the opened workbook.
 
Upvote 0
Please let me suggest that you move the code for the Import function to a code module.
Change the code in the command button "Import_Click" to merely call the "Public" subroutine in the code module.

If you should happen to delete the Sheet1, then all of the code associated with it gets deleted as well.
Making the sub procedure in the code module "Public" should make sure that it's exposed to other workbooks to call as well.
 
Upvote 0
I cannot modify the original template that contains the Import. The template is utilized for more than just what I am doing through out a large group.

If I make an edit to the 3 independent files, they will get left out should there be revisions to CMM programs down the road. (There are ALWAYS CMM program revisions down the road).
Thank you for your help! I will see if there is another way to get there with all the information I've collected.
 
Upvote 0
For your purposes does the code need to be run from the original template?
 
Upvote 0
Yes, unfortunately. If I don't, then the csv file will be deleted and the data will not be retained in the file. There have been instances where I re-perform this data collection routine with past units. So I wanted an all in 1.

(Additionally, I would need to re-draft my current project to search down through the csv file if it errors out.)~New thought with lost functionality
That is actually a something within my limits to perform. I just wish I could force the functionality, but thanks for giving me the thought!
 
Upvote 0
The data won't be retained in what file?

Also, why would the CSV be deleted?

Even if the original code did the above couldn't you copy it and adjust it so it doesn't.
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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