runtime error 104

Redhawk

New Member
Joined
Aug 12, 2005
Messages
24
Good day everyone.
I have written a macro, and linked it to a control, to open an existing workbook and then to insert text in a specific cell(group of cells, the cells are merged). Regardless of what i change i keep on getting a runtime error 1004.

Here is the code i used:

Private Sub CommandButton1_Click()

' INSERTWHSQINWO Macro
' This macro inserts the white melamine squareline finish in the works order

Workbooks.Open Filename:="E:\Leisure Kitchens\NCS\PM.xls", UpdateLinks _
:=3
Range("F4:J6").Select
ActiveCell.FormulaR1C1 = "WHITE MELAMINE SQUARELINE"
With ActiveCell.Characters(Start:=1, Length:=25).Font
.Name = "Tahoma"
.FontStyle = "Regular"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

End Sub

Any suggestions would be greatly appreciated.

Thanks
Red
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
It is necessary to say on which line of code the error occurs.
I have tested your code without the 'Workbooks.Open' line and it works OK.
Perhaps you have got the path/filename wrong
perhaps you need to activate the correct worksheet.
 
Upvote 0
Hi, thanks for the response.
The error occured, at
"Range("F4:J6").Select"

I have checked the path and file name and it is correct, hence my confusion

Red
 
Upvote 0
I think you must have the wrong range. Are you sure that those are the merged cells ? Are you sure that you have the correct worksheet active ?
As I said, my test worked OK.
 
Upvote 0
The take focus on click is set to false. The range is correct and the macro runs perfectly until i put it behind the control button. Then i still get the same range error as before???Bizzare or what?

I appreciate the effort

Thanks

Red
 
Upvote 0
Bizzare or what?
not at all!
your buttoncode always refers to the sheet where it is located
Range(...) cannot be selected since it means
Sheets("sheetwherebuttonislocated").Range(...).select
since the sheet is not active you cannot select anything on it...

what you mean is to select cells on the sheet in the other workbook
so as Steve pointed out you probably need
ActiveWorkbook.range("F4:J6").select
EDIT: see correction below !

kind regards,
Erik
 
Upvote 0
Try this
Code:
ActiveWorkbook.ActiveSheet.Range("F4:J6").Select

And so did this.
Code:
    With ActiveWorkbook.ActiveSheet.Range("F4:J6")
        .Value = "WHITE MELAMINE SQUARELINE"
        With .Font
            .Name = "Tahoma"
            .FontStyle = "Regular"
            .Size = 14
        End With
    End With

Erik

There is no Range method/object of a workbook.
 
Upvote 0
Norie,
thanks for correcting this
if you read my explanation
what you mean is to select cells on the sheet in the other workbook
there is
what you mean is to select cells on the sheet in the other workbook
I should have verified the syntax which was provided earlier, so this would have been what was correctly formulated in words

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,036
Members
449,062
Latest member
mike575

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