Welcome to Dream.In.Code
Become a VB Expert!

Join 149,947 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,384 people online right now. Registration is fast and FREE... Join Now!




VB and Excel

 
Reply to this topicStart new topic

VB and Excel, How do i open the window

vb6_god
16 Jan, 2008 - 03:48 AM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 26


My Contributions
OK so i have this problem i am using automation to manipluate data from vb to an excel worksheet, that works fine the problem is that i need to open the application itself after processing this data....so that the user can see the actual workbook. I have no idea how i can run the application from VB ..... any ideas

CODE
Dim xl As New Excel.Application  'opens an excel application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Dim a
Set xlwbook = xl.Workbooks.Open("E:\Ass2 Programming\Timesheet.xls")
Set xlsheet = xlwbook.Sheets.Item(1)

a = 5  'row number to start at in excel sheet

            If Not dta_emp.Recordset.EOF Then dta_emp.Recordset.MoveFirst 'moves to the first record
              Do While Not dta_emp.Recordset.EOF
            
                xlsheet.Cells(a, 1) = txtfname.Text
                xlsheet.Cells(a, 2) = txtrate.Text
                xlsheet.Cells(a, 3) = DateDiff("h", mi.Text, mo.Text)   'difference between the sign in and out by hours
                xlsheet.Cells(a, 4) = DateDiff("h", ti.Text, tot.Text)
                xlsheet.Cells(a, 5) = DateDiff("h", wi.Text, wo.Text)
                xlsheet.Cells(a, 6) = DateDiff("h", thi.Text, tho.Text)
                xlsheet.Cells(a, 7) = DateDiff("h", fi.Text, fo.Text)
                xlsheet.Cells(a, 8) = DateDiff("h", sai.Text, sao.Text)
                xlsheet.Cells(a, 9) = DateDiff("h", si.Text, so.Text)
                xlwbook.Save
            
            a = a + 1
            dta_emp.Recordset.MoveNext
         Loop
        
     xlwbook.Sheets.PrintPreview    ' PRINT PREVIEW !!!!!! DOESNT WORK
    xl.ActiveWorkbook.Close False, "Timesheet.xls"  'saves the file
   xl.Quit 'quits the application



i would preferably like to open the file via a print preview, but i gave up on that lol
thanx again peeps
User is offlineProfile CardPM
+Quote Post

vb6_god
RE: VB And Excel
16 Jan, 2008 - 03:59 AM
Post #2

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 26


My Contributions
Never mind people i have now found an easy way to print it out
most obvious actually DUH TO ME !!!

CODE
xlwsheet.printout



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 05:17PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month