PDA

View Full Version : Solved: Creating new worksheets



Ashes.cfg
09-28-2007, 07:46 AM
Hi guys,
This is my problem..I hope i give you exact details
I have write a code which will perform the following

It should open a workbook
It should write the data in the default worksheets if they are empty...If they are not empty then it should create new worksheets and write the data on them.

Would prefer if the creating new worksheets and write the data in them would be one function as i would to recall it several times!

actually i need to write it in perl..but if i can get it to work in vba i can modify it!

Bob Phillips
09-28-2007, 07:59 AM
Here is a shot at it



Dim sFile As String

sFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If sFile <> False Then
Workbooks.Open Filename:=sFile
With ActiveWorkbook
If .Worksheets(1).UsedRange.Cells.Count = 1 Then
If .Worksheets(1).Range("A1").Value = "" Then
.Worksheets(1).Range("A1").Value = Date
.Worksheets(1).Range("A1").NumberFormat = "dd mmm yyyy"
Else
.Worksheets.Add after:=.Worksheets.Count
.Worksheets(.Worksheets.Count).Range("A1").Value = Date
.Worksheets(.Worksheets.Count).Range("A1").NumberFormat = "dd mmm yyyy"
End If
Else
.Worksheets.Add after:=.Worksheets.Count
.Worksheets(.Worksheets.Count).Range("A1").Value = Date
.Worksheets(.Worksheets.Count).Range("A1").NumberFormat = "dd mmm yyyy"
End If
End With
End If

Ashes.cfg
09-28-2007, 11:26 AM
thanks!