# excel add sheet vbs



## teeheiman (Jul 17, 2006)

Im useing the excel com application to create a excel file but when I create the sheets it doesnt come in order, is there any way I can add the sheet so that it  adds it after and not before the deafult 3?

```
wrk.sheets.add()
```

Thanks,
Billy


----------



## VoG (Jul 17, 2006)

Something like 


```
Sub tst()
Sheets.Add after:=Sheets("sheet2")
End Sub
```


----------



## Von Pookie (Jul 17, 2006)

In VBA it would be 
	
	
	
	
	
	



```
Sheets.Add After:=Sheets(Sheets.Count)
```


----------



## teeheiman (Jul 17, 2006)

Do you know the vbs code for this though?


----------



## Von Pookie (Jul 17, 2006)

I don't, no. This isn't a VBS forum, anyway. Moving your post to the "Other questions" forum...


----------



## Legacy 98055 (Jul 17, 2006)

This is the most generic way to do this.  I am assuming the the 'wrk' variable is a reference pointing to a workbook and not the application...

wrk.sheets.add ,wrk.sheets(wrk.sheets.count)


----------



## teeheiman (Jul 17, 2006)

Sweet!
Great thank you very much! Works Perfect!

Also im not sure if its possible but what about being able to to create boarders on certain cells?

Thanks


----------



## Legacy 98055 (Jul 17, 2006)

Sure it's possible. The same object model that is available to VBA is available to VBScript.  If fact, I use the VBA IDE when I write VBScript interfacing with Excel with, usually, very little editing being needed.  There are differences in the two variants of the language, but when working with a model such as Excel, you should run into very few problems...


----------



## teeheiman (Jul 17, 2006)

VBA IDLE? also can you possibly post some code?

Thanks,
BIlly


----------



## Legacy 98055 (Jul 17, 2006)

Should have said VBA Editor.  VBA IDE is the VBA Interface Development Environment.  (I think...)


----------



## teeheiman (Jul 17, 2006)

Im useing the excel com application to create a excel file but when I create the sheets it doesnt come in order, is there any way I can add the sheet so that it  adds it after and not before the deafult 3?

```
wrk.sheets.add()
```

Thanks,
Billy


----------



## teeheiman (Jul 17, 2006)

Ya ive went in and tried to make the vba but im not really sure how I would set it to go on the correct cell that I wanted to put the boarder on.

```
With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
```

Thanks


----------



## Legacy 98055 (Jul 17, 2006)

To debug vbscript compatible code, simply use late-binding with all object variables...  This code will compile in VBA and VBScript except for the ThisWorkbook reference.  You will need to use CreateObject or GetObject or the Shell...


```
Sub Example()
    Dim wrk As Object
    Dim sh As Object
    
    Set wrk = ThisWorkbook
    
    
    
    Set sh = wrk.Sheets.Add(, wrk.Sheets(wrk.Sheets.Count))
    
    With sh.Range("A1").Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

End Sub
```


----------

