0

I've looked on some similar question of "Object required on calling sub", but None of them seems to help with my problem. I want to call a sub(for example, in sheet2) from a sub in sheet1 like

Private Sub Worksheet_Activate()
ThisWorkbook.ActiveSheet.Cells.Clear
Call sheet2.generate  <== where the error comes from
End Sub

where generate is the sub name on sheet2 which don't require any parameter but it tells me that Object required and sendback an error. I've tried:

without using call

sheet2.generate 

without sheet name

generate
call generate

and adding a useless parameter for calling( also added to generate sub)

call sheet2.generate(1)

but it's not working too, so i detele that parameter as it have no use in the code.

there is no problem on generate sub(which i test for many time)

still, all of the above do not work for me, can someone provide a vaild way to solve this?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
okie
  • 847
  • 6
  • 18
  • Do you in fact have a sheet with a [code name](https://stackoverflow.com/a/54501849/11683) of `sheet2`? – GSerg Dec 19 '19 at 00:24
  • i am using chinese version of excal tho... so the codename is in chinese, and i am calling it using the normal name – okie Dec 19 '19 at 00:25
  • 2
    No, you are calling it using the code name. If `sheet2` was the normal name, you would have used `Worksheets("sheet2").generate`. – GSerg Dec 19 '19 at 00:26
  • @GSerg, so i should call it with code name? – okie Dec 19 '19 at 00:28
  • 2
    @WhereisourMonica You can use either. But you cannot use the normal name as a code name or vice versa. Unless, of course, you make them the same. – GSerg Dec 19 '19 at 00:29
  • no,i just use "sheet2" as example, the real name i replace with is called "hiddenreveal". – okie Dec 19 '19 at 01:11
  • maybe the problem is at the generate sub? Cause it seems like I ```Dim``` a Int inside the sub. Which maybe make the problem? – okie Dec 19 '19 at 02:11
  • VBA doesn't get to the `Generate` sub, it stops at the dot in `Sheet2.` and says "wait a minute, that's not an object!" - make sure your module says `Option Explicit` at the top. Then try `Application.Run "'name of the sheet'!Generate"` – Mathieu Guindon Dec 19 '19 at 05:01
  • Consider adding a standard module to your VBA project, and moving the `Generate` procedure there; then, just `[Call] Generate` will be enough to invoke it. – Mathieu Guindon Dec 19 '19 at 05:02

1 Answers1

0

I've found that the problem is not at calling function,but instead, stuffs INSIDE function have problem, and debug arrow goes function and says "error 1004", after fixing some variable problem of the function, the problem no longer shows.

BRUH

okie
  • 847
  • 6
  • 18