ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Making worksheets (https://www.excelbanter.com/excel-programming/365641-making-worksheets.html)

Fabrizio

Making worksheets
 
Hi. I have a makro that displays a userform that can generate a report. The
report is to be created when the user presses a button on the user form. The
report is to be shown in a new worksheet that the program creates. I want the
new worksheet to have certain settings (e.g. no gridlines). I am trying to
write code for this but I do not know how to refer to the worksheet without
using the very unconvenient code when setting one worksheet active and then
applying the changes. Code:

Private Sub worksheetMaker()
Dim WB As Workbook
Dim SH As Worksheet
Dim iCtr As Long
Const sName As String = "Rapport "
Set WB = ActiveWorkbook
iCtr = WB.Worksheets.Count
Set SH = Worksheets.Add(after:=Worksheets(iCtr))
SH.Name = sName & iCtr
'Sheets(SH.Name).Select
'Cells.Select
Sheets(SH.Name).DisplayGridlines = False

The last line is wrong. How do you wirte this so that it works? Please help
me!

Duncan[_5_]

Making worksheets
 
activate the correct window and then

ActiveWindow.DisplayGridlines = False

worked for me, I dont think it likes it applied to the sheet property
and not the window.

Duncan

Fabrizio wrote:

Hi. I have a makro that displays a userform that can generate a report. The
report is to be created when the user presses a button on the user form. The
report is to be shown in a new worksheet that the program creates. I want the
new worksheet to have certain settings (e.g. no gridlines). I am trying to
write code for this but I do not know how to refer to the worksheet without
using the very unconvenient code when setting one worksheet active and then
applying the changes. Code:

Private Sub worksheetMaker()
Dim WB As Workbook
Dim SH As Worksheet
Dim iCtr As Long
Const sName As String = "Rapport "
Set WB = ActiveWorkbook
iCtr = WB.Worksheets.Count
Set SH = Worksheets.Add(after:=Worksheets(iCtr))
SH.Name = sName & iCtr
'Sheets(SH.Name).Select
'Cells.Select
Sheets(SH.Name).DisplayGridlines = False

The last line is wrong. How do you wirte this so that it works? Please help
me!



Duncan[_5_]

Making worksheets
 
or if you know the name or index of the window you have created then
you can do

Windows (Index).DisplayGridlines = False

which should also work and then you dont need to activate.

Duncan


Duncan wrote:

activate the correct window and then

ActiveWindow.DisplayGridlines = False

worked for me, I dont think it likes it applied to the sheet property
and not the window.

Duncan

Fabrizio wrote:

Hi. I have a makro that displays a userform that can generate a report. The
report is to be created when the user presses a button on the user form. The
report is to be shown in a new worksheet that the program creates. I want the
new worksheet to have certain settings (e.g. no gridlines). I am trying to
write code for this but I do not know how to refer to the worksheet without
using the very unconvenient code when setting one worksheet active and then
applying the changes. Code:

Private Sub worksheetMaker()
Dim WB As Workbook
Dim SH As Worksheet
Dim iCtr As Long
Const sName As String = "Rapport "
Set WB = ActiveWorkbook
iCtr = WB.Worksheets.Count
Set SH = Worksheets.Add(after:=Worksheets(iCtr))
SH.Name = sName & iCtr
'Sheets(SH.Name).Select
'Cells.Select
Sheets(SH.Name).DisplayGridlines = False

The last line is wrong. How do you wirte this so that it works? Please help
me!



Don Guillett

Making worksheets
 
try this

Sub AddSheetandName()
Sheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Rapport"
ActiveWindow.DisplayGridlines = False
End Sub

--
Don Guillett
SalesAid Software

"Fabrizio" wrote in message
...
Hi. I have a makro that displays a userform that can generate a report.
The
report is to be created when the user presses a button on the user form.
The
report is to be shown in a new worksheet that the program creates. I want
the
new worksheet to have certain settings (e.g. no gridlines). I am trying to
write code for this but I do not know how to refer to the worksheet
without
using the very unconvenient code when setting one worksheet active and
then
applying the changes. Code:

Private Sub worksheetMaker()
Dim WB As Workbook
Dim SH As Worksheet
Dim iCtr As Long
Const sName As String = "Rapport "
Set WB = ActiveWorkbook
iCtr = WB.Worksheets.Count
Set SH = Worksheets.Add(after:=Worksheets(iCtr))
SH.Name = sName & iCtr
'Sheets(SH.Name).Select
'Cells.Select
Sheets(SH.Name).DisplayGridlines = False

The last line is wrong. How do you wirte this so that it works? Please
help
me!





All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com