URGENT Please help! create excel workbook & 3 spreadsheets

Hi Im stuck with generating some excel files in a directory folder using VB.NET

Please help me to:
2. Create an excel workbook (Im using Office 2003)
3. Create 3 named sheets in the workbook

Just looking for some code that works & dont care if its messy as long as it works

Thanks heaps!
LVL 1
craigdevAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bruintjeConnect With a Mentor Commented:
Hello craigdev,

used a button on a form for this
---------
Public Class Form1

    'source: http://dotnetjunkies.com/WebLog/dinakar/articles/16282.aspx
    Function CreateNewFolder(ByVal Path, ByVal NewFolderName)

        Dim objFSO As Object
        objFSO = CreateObject("Scripting.FileSystemObject")
        Dim FullPath As String
        FullPath = Path & NewFolderName
        If Not objFSO.FolderExists(FullPath) Then
            objFSO.CreateFolder(FullPath)
            CreateNewFolder = True
        Else
            CreateNewFolder = False
        End If
        objFSO = Nothing

    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xlObj As Object, mysheet As Object
        Dim strSheet As String, sheetCount As Integer
        Dim strPath As String, strFolder As String

        strPath = "c:"
        strFolder = "myfolder"
        CreateNewFolder(strPath, strFolder)
        xlObj = CreateObject("Excel.Application")
        xlObj.visible = True
        xlObj.workbooks.add()
        ' now we first need a count of the default sheets on this pc
        sheetCount = xlObj.workbooks(1).sheets.count
        Select Case sheetCount
            Case 1
                xlObj.workbooks(1).sheets(1).name = "MySheet1"
                mysheet = xlObj.workbooks(1).sheets.add()
                mysheet.name = "MySheet2"
                mysheet = xlObj.workbooks(1).sheets.add()
                mysheet.name = "MySheet3"
            Case 2
                xlObj.workbooks(1).sheets(1).name = "MySheet1"
                xlObj.workbooks(1).sheets(2).name = "MySheet2"
                mysheet = xlObj.workbooks(1).sheets.add()
                mysheet.name = "MySheet3"
            Case 3
                xlObj.workbooks(1).sheets(1).name = "MySheet1"
                xlObj.workbooks(1).sheets(2).name = "MySheet2"
                xlObj.workbooks(1).sheets(3).name = "MySheet3"
        End Select
        xlObj.workbooks(1).saveas("myworkbook")
    End Sub
End Class
---------

hope this helps a bit
bruintje
0
 
craigdevAuthor Commented:
Awesome!!! Thanks Buddy!
0
 
bruintjeCommented:
good luck! and thanks for the grade :)
0
 
craigdevAuthor Commented:
... just another quick q,

how to I save the workbook to the folder, in the example above, C:/myfolder?
0
 
craigdevAuthor Commented:
nah its fine, all finished, CHEERS
0
All Courses

From novice to tech pro — start learning today.