VBA to perform 'click' function

R2ah1ze1l

Board Regular
Joined
Nov 10, 2017
Messages
93
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?
 

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".
Firstly! Thank you Pat for your response:

try
Code:
Worksheets("DATA").Select
Worksheets("DATA").Activate
Call Import_Click

However,
I get an error Sub or Function not defined.
Look through the help menu and it tells me to add a reference.
I go to tools and 'reference' is greyed out. What other way around is there? I could declare it in the begining of my code, however I'm not sure the propper As "" to populate. I have tried
Code:
Dim Import_Click As Object
Dim Import_Click As VBAProject
Dim Import_Click As Action
Dim Import_Click As VbCallType

Unfortunately a lot of this is guess work to me right now. I will answer just about any questions to get the information needed to allow this functionality to be generated.
 
Upvote 0
What exactly is this 'click' function?

Is it event code associated with a button/shape?
 
Upvote 0
I guess that I assumed that you had created a command button from the Developer\Insert\ActiveX or Form menu, and created the code associated with the click event of the button.
 
Upvote 0
I have an Excel file that pulls and reformats csv data. There is a button in this file to click and it will import the csv and never overwrite any lines. I use this file for a host of different things and it was developed by a more advanced VB programmer.

Now I have generated a separate Excel file that allows me to identify locations that need further analysis based on conditions built to my new template file. In this file I use a serial number to find the column(s) and am copying the data from the original file above to my current file. The localized information has allowed me to do some other things within the various sheets(I do what I can with what I know).

I want to be able to refresh (import current data) the original file prior to searching the document. Traditionally, the moment the csv file is generated, thats the data I'm being requested to get populated in the new file. I have 3 files that would require the update currently, if this NEW file can cause the 'click' function then I may be able to remove myself from being a middle-man.

I hope I explained this well.
 
Upvote 0
I guess that I assumed that you had created a command button from the Developer\Insert\ActiveX or Form menu, and created the code associated with the click event of the button.

I have generated a 'click' button in my current file. I'm trying to make this one perform the click in a seperate file. I have seen that a private function could be performed from another private function. That was my original code structure, for some reason it just bypasses the line as if it doesn't exist. As in, does not cause the click event and update the original file.
 
Upvote 0
If the code this 'click' function executes is in another workbook you'll first have to open the workbook with the code.

Once that's done you can use Application.Run to run the other code but I would suggest you actually call the code that the 'click' function executes rather than call the 'click' function itself.
 
Upvote 0
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
 
Last edited:
Upvote 0
If the code this 'click' function executes is in another workbook you'll first have to open the workbook with the code.

Once that's done you can use Application.Run to run the other code but I would suggest you actually call the code that the 'click' function executes rather than call the 'click' function itself.

Thank you, I will try this once I am done with my upcomming meeting! This seems to be of high potential!
 
Upvote 0

Forum statistics

Threads
1,223,150
Messages
6,170,377
Members
452,323
Latest member
robertbs021

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