excel vba - Getting sheet by index causes error in vba macro -


i'm trying create macro in excel, following code causes error. can't why

public sub createsimplemodel()      dim reportsheet worksheet     msgbox thisworkbook.sheets.count      reportsheet = thisworkbook.sheets(1) <-- here error  end sub 

the message box appears shows there sheets in workbook. error object variable or block not set appreciated.

you need use "set" if want reference workbook

public sub createsimplemodel()      dim reportsheet worksheet     msgbox thisworkbook.sheets.count      set reportsheet = thisworkbook.sheets(1)  end sub 

Comments

Popular posts from this blog

c# SetCompatibleTextRenderingDefault must be called before the first -

How to prevent logback from emitting repeated "Empty watch file list. Disabling" messages -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -