Run-time error '1004'

PeterBunde

New Member
Joined
Dec 7, 2016
Messages
45
Folks!

My .xls file is stored on a Confluence page. When I download it, I have to press the activate editing button - which results in an error message:

Run-time error '1004' Method 'Sheets' of object '_Global' failed

The code that fails is:

Code:
Value_ = Sheets(workingsheet).Cells(param2, param1).Value()

I substituted the variable names with the real values and put it in a function then ran it, and the code runs fine:

Code:
MsgBox(Sheets("defects_of_category_store").Cells(1, 1).Value())

I should tell you that the sheet "defects_of_category_store" is hidden (I use it to store an array which I then re-load into memory when the sheet is opened).

(If you could tell me how, I would attach the file)

BW Peter B Hansen
 
No attachments are allowed on this form. Use a free shared site like dropbox.com to post links to a short simple file that duplicates the problem.

Now that we know that it is a class, what is the code that uses it that causes the error?

To post all of a sheet's code, right click the tab, View Code, select and then copy and paste here.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Value_ = Sheets(workingsheet).Cells(currentRow, param1).Value
This sheds a little light on it. The statement is relatively simple. You have three variables, 'workingsheet' should be a string value for the sheet name. 'currentRow' and 'param1' should both be integer values representing row and column. If the string value is not a valid sheet name you would get error 9, subscript out of range and if the compiler has a problem deciding what data type 'workingsheet' is other than string, you might get error 1004. If the either or both of the other two variable values are not integer values, they you could get either error 13, type mismatch when searching for a range, or error 1004 when trying to return a value from it as a range. In this case it seems to be the latter. You can check the values of the variables at run time by using the F8 function key with the vb editor open and step through the code, or use the watch window to monitor the variable values.
 
Upvote 0
Sorry, I was late for a doctor appointment and had to cut short. Adding to post #12 , if you find that the integer values are not being returned for the Cells() range, then you need to review the prior code to see where the wrong value was originated. You can use the mouse pointer as you step through the code to view the variable values in the intelisense (tool tip) display. This is a debug method which I use, but I cannot do it for you from here.
 
Upvote 0
ActiveWorkbook alone will show Nothing becaus it is a constant object, but it should return something for
Code:
ActiveWorkbook.Name
 
Last edited:
Upvote 0
I found a workaround.

In the event handler for opening the workbook, I set a flag if the workbook isn't recognised. Using that flag, I can then run the code I want at a later stage - because once the workbook has opened, it does recognise the workbook a in
Code:
Set wb = ThisWorkbook
.

Code:
Private Sub Workbook_Open()
there_is_a_problem = False
On Error GoTo problem_handler
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
<My code that crashes if the sheet doesn't know>
Exit Sub
problem_handler:
    there_is_a_problem = True 'Will load stats when envoked, see next function
End Sub
 
Upvote 0
I found a workaround.

In the event handler for opening the workbook, I set a flag if the workbook isn't recognised. Using that flag, I can then run the code I want at a later stage - because once the workbook has opened, it does recognise the workbook a in
Code:
Set wb = ThisWorkbook
.

Code:
Private Sub Workbook_Open()

there_is_a_problem = False
On Error GoTo problem_handler
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
<my know="" doesn?t="" sheet="" the="" if="" crashes="" that="" code="">
Exit Sub
problem_handler:
    there_is_a_problem = True 'Will load stats when envoked, see next function
End Sub

glad you worked it out and thanks for the feedback.
regards, JLG</my>
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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