Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Go Back  Xtreme Visual Basic Talk > > > Excel 2010 VB.net 2012 Automation


Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2014, 04:16 PM
sourcegin sourcegin is offline
Newcomer
 
Join Date: Sep 2014
Posts: 2
Smile Excel 2010 VB.net 2012 Automation


what i'm attempting to do is write values to an excel spreadsheet , i don't want the workbook to open , i just wanna write the values without overwriting the values from yesterday or the day before ,
can someone guide me or maybe even show me how to accomplish this better

this is what i have on a button click for right now

'---------------//Code starts here //-------------------------
'// Data insert to excel
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim myDay As String
Dim MyMonth As String
Dim MyYear As String
Dim offset As String
Dim Mydirectory As String
Dim MyExtension As String
Dim MyFileName As String
Dim FileCheck As String
Dim c1 As String
Dim time As DateTime = DateTime.Now
'xlApp.DisplayAlerts = False
offset = 9

'get month
myDay = Format(Now, " d ")
MyMonth = Format(Now, " mm ")
'get year
MyYear = Format(Now, " yyyy ")
'working directory
Mydirectory = "C:\REPORT\"
'----Start Excel---------------------------------------------
'Excel extension
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("C:\REPORT\report.xlsx")
xlWorkSheet = xlApp.Worksheets("Daily")

xlApp.DisplayAlerts = False
' xlWorkBook = xlWorkSheet(1)

xlApp.Visible = False
c1 = 234
' Need the 12,19,19 to be replace by the Current day of the month myday but remed out statements do not work
xlApp.Cells(19 + offset, 2).Value = DateTime.Now
xlApp.Cells(19 + offset, 3).Value = 123 'mData0 old display value variable
xlApp.Cells(19 + offset, 4).Value = 234 'mData0 old display value variable
' xlApp.Cells(myDay + offset, 5).Value = 345 'mData0 old display value variable
' xlApp.Cells(myDay + offset, 6).Value = 456 'mData0 old display value variable

With xlApp.ActiveSheet
.Columns.AutoFit()
' .ColumnWidth = .ColumnWidth * 2.5
'.HorizontalAlignment = xlCenter
xlWorkBook.Saved = True
xlWorkBook.Close(SaveChanges:=True)
xlApp.Quit()
xlApp.DisplayAlerts = False

xlApp = Nothing
xlWorkBook = Nothing
xlWorkSheet = Nothing

End With

End Sub
Reply With Quote
  #2  
Old 10-09-2014, 08:47 PM
Rapiant's Avatar
Rapiant Rapiant is offline
Centurion
 
Join Date: Jun 2008
Location: Iowa
Posts: 111
Default

You forgot to include xlWorkbook.save() in your code. if you don't want to override values you need to have your code look at the values in your cells in then find the first empty cell.

Dim EmptyRow As Long
EmptyRow = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0).Row
__________________
--Adam Lee--

Website
My Blog
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
 
Excel 2010 VB.net 2012 Automation
Excel 2010 VB.net 2012 Automation
 
-->