To make a single sheet the active sheet, use the activate method. Here is the example syntax to select worksheet using vba. Select worksheet with vba code name sheet1.select. Web vb worksheets (sheet1).activate activesheet.pagesetup.orientation = xllandscape activesheet.printout this example uses the beforedoubleclick event to open a specified set of files in notepad. Thisworkbook.sheets (n&a).range (b4:f16).select however this works: Sub importfile () application.screenupdating = false dim parentworkbook as excel.workbook dim otherworkbook as excel.workbook dim workbookname as variant set parentworkbook = activeworkbook workbookname =. More activate / select sheet examples. I don't know why the following is not working: If you want to select a worksheet instead of activating it you can use.select in the above codes instead of activate command. If we want to selects any single cell or collection of cells, then we use select worksheet method.
Web vb worksheets (sheet1).activate activesheet.pagesetup.orientation = xllandscape activesheet.printout this example uses the beforedoubleclick event to open a specified set of files in notepad. If you want to specify the workbook for the sh1 variable, do it in your set line: Web vb worksheets (sheet1).activate activesheet.pagesetup.orientation = xllandscape activesheet.printout this example uses the beforedoubleclick event to open a specified set of files in notepad. Set sh1 = wb1.sheets (sheet1) and then you can check what workbook it's a part of by looking at it's.parent.name property: I keep on getting a run time error code 9. Web assuming sheet1 is the name of the sheet that you want to select. This code line selects a worksheet based on its sheet tab name Select worksheet with vba code name sheet1.select. Web to select a sheet or multiple sheets, use the select method. More activate / select sheet examples. To select the current worksheet, use the activesheet object: