0

I created a code for creating Named Ranges in Excel using Range object but didn't work as it works in VBA. Error comes in the statement where I try to create a Range object, not sure how this could be done.

If anyone could suggest me an idea it would great.

Set Exobj = CreateObject("Excel.Application")
Set Newbook = Exobj.Workbooks.Add()
Newbook.SaveAs("C:\Users\ACER\Desktop\Project Folder\Test17.xlsx")

Exobj.Workbooks.Open("C:\Users\ACER\Desktop\Project Folder\Test17.xlsx")
Exobj.Visible = True

Set Myrange = Exobj.Worksheets(sheets1).Range("A1:H11") ' statement where Error comes

For each C in Myrange
If c.Value = "" Then 
C.Value ="Blank"
End if
Next

Exobj.Workbooks.Save()
Exobj.Activeworkbooks.Close()
4
  • 2
    I think you need to surround sheets1 with quotes, i.e. Set Myrange = Exobj.Worksheets("sheets1").Range("A1:H11") Commented Feb 26, 2013 at 0:43
  • Than you, its working. Commented Feb 26, 2013 at 2:42
  • I'll post my comment as answer, cheers ;) Commented Feb 26, 2013 at 17:06
  • :) similar problem i faced when i used Next C it did not work, but when i made it Next only it worked Commented Apr 15, 2016 at 13:16

1 Answer 1

1

I think you need to surround sheets1 with quotes, i.e.

Set Myrange = Exobj.Worksheets("sheets1").Range("A1:H11") 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.