473,480 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems Automating Excel from Vb

3 New Member
Firstly i should mention that Im relativey New to VB, and programming in general - Only starting in the last 12 months or so for school, So plz dont take anything for granted and act like i know nothing :)

Im making a program at the moment which should be able to create (or load) a database, then edit it from the users input - sort of like an order form type of thing.

I Used excel for my database - against the advice of my teacher who likes Access, but i was unable to use it at the time - and have been able to manage to get by so far, however now i keep getting a "ComException was unhandled" Error.



Expand|Select|Wrap|Line Numbers
  1.     Private Sub DBASEdefaultVals()
  2.  
  3.         For i = 2 To 61 Step 11
  4.  
  5.             xlSheet.Cells(i, 1).value = "Depot " + CStr(i)
  6.             xlSheet.Cells(i + 1, 1).Value = "TYPE A"
  7.             xlSheet.Cells(i + 2, 1).Value = "TYPE B"
  8.             xlSheet.Cells(i + 3, 1).Value = "TYPE C"
  9.             xlSheet.Cells(i + 4, 1).Value = "TYPE D"
  10.             xlSheet.Cells(i + 5, 1).Value = "TYPE E"
  11.             xlSheet.Cells(i + 6, 1).Value = "TYPE F"
  12.             xlSheet.Cells(i + 7, 1).Value = "TYPE G"
  13.             xlSheet.Cells(i + 8, 1).Value = "TYPE H"
  14.             xlSheet.Cells(i + 9, 1).Value = "TYPE I"
  15.             xlSheet.Cells(i + 10, 1).Value = "TYPE J"
  16.  
  17.         Next
  18.  
  19.         xlSheet.Cells(1, 1).Value = "DATE"
  20.  
  21.         'Figures out the number of days in the user indicated amount of years by subtracting the current date from the date as it will be in the specified amount of years
  22.  
  23.         TSDayRec = DateTime.Today.AddYears(YearsToLog) - DateTime.Today
  24.         IntDayRec = TSDayRec.Days
  25.  
  26.         For i = 1 To IntDayRec
  27.             xlSheet.Cells(1, i + 1).value = DateTime.Today.AddDays(i)
  28.  
  29.             For a = 1 To 10
  30.                 xlSheet.Cells(2 + a, i + 1).value = QtyDepot1(a)
  31.                 xlSheet.Cells(13 + a, i + 1).value = QtyDepot2(a)
  32.                 xlSheet.Cells(24 + a, i + 1).value = QtyDepot3(a)
  33.                 xlSheet.Cells(35 + a, i + 1).value = QtyDepot4(a)
  34.                 xlSheet.Cells(46 + a, i + 1).value = QtyDepot5(a)
  35.  
  36.             Next
  37.         Next
  38.  
  39.  
  40.  
  41.     End Sub
I Only get the error in the underlined area. Before that it runs fine.


Also another small problem, i have a SaveFileBox where the user indicates a place to svae the file, and the database is saved at that location. Ive got teh box working fine, im jsut a bit lost of how to save the file at that spot.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub SaveDatabase()
  2.         SaveFileDialog1.ShowDialog()
  3.         WhatFile = SaveFileDialog1.FileName
  4.  
  5.         If My.Computer.FileSystem.FileExists(WhatFile) Then
  6.             intReply = MsgBox(WhatFile & " already exists. Would you like to overwrite it?", YesNoCancel Or Exclamation, "Overwrite File?")
  7.             If intReply = 2 Then
  8.                 Exit Sub
  9.             ElseIf intReply = 6 Then
  10.                 xlBook.SaveAs(WhatFile)        
  11.             Label6.Text = "Successfully Saved"
  12.             ElseIf intReply = 7 Then
  13.                 SaveDatabase()
  14.             End If
  15.  
  16.         End If
  17.     End Sub
The file doesnt save in the spot inicated - or as far as i can tell at all .. I dont think the underlined part uses the correct syntax, but i dont know what else it could be.. Any Ideas?
Jul 9 '07 #1
2 1312
DvsStyle
3 New Member
Sorry to Pop so many questions on you at once, but in the part of my code where i try write the values in Excel, it has to enter hundreds - if not thousands - of values into it, depending on the size of the variable IntDayRec. I was wondering if anyone knew a more efficiant way to achieve this than teh couble loop im using at the moment, as im sure having an hour long wait wouldnt be appealing to anyone using a program...

Expand|Select|Wrap|Line Numbers
  1. For i = 1 To IntDayRec
  2.             xlSheet.Cells(1, i + 1).value = DateTime.Today.AddDays(i)
  3.  
  4.             For a = 1 To 10
  5.                 xlSheet.Cells(2 + a, i + 1).value = QtyDepot1(a)
  6.                 xlSheet.Cells(13 + a, i + 1).value = QtyDepot2(a)
  7.                 xlSheet.Cells(24 + a, i + 1).value = QtyDepot3(a)
  8.                 xlSheet.Cells(35 + a, i + 1).value = QtyDepot4(a)
  9.                 xlSheet.Cells(46 + a, i + 1).value = QtyDepot5(a)
  10.  
  11.             Next
  12.  
  13.         Next
Sorry agani for dumping so much here and seeming to push you into it, but ive only got another week or so to finish this and im totally stumped...
Jul 10 '07 #2
DvsStyle
3 New Member
I Just realised My probelm with the saving of the file, was a total noob mistake that resulted totally from not looking over it properly...

So Feel free to point and laugh at me for that stupid mistake....

Ive fixed it now so thats good noone needs tos help me witht hat anymore.

But my 1st - major - problem and the one in the 2nd post are still bothering me if anyone can help.

Please?

Thanks
Jul 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1780
by: Nick Carter | last post by:
The following C# lines of code work fine with Excel 2000:- ExcelApplication excelApplication = new Excel.Application(); ExcelWorkbook excelWorkbook =...
0
1427
by: Laurence | last post by:
Hi Folks hope someone can help me out with this wee problem. I'm automating Excel from A2K and want to put a solid black border around a range of cells. I've tried using this: ...
22
15311
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
0
2099
by: David Caissie | last post by:
I am trying to automate a Vb.net chart using the excel COM object. The problem occurs when trying to run the code in different systems. It is working fine under one of my computers but once i move...
1
17927
by: chris_j_adams | last post by:
Hi, I'm trying to use Excel VBA ('97) to send details from an Excel sheet to a web page. I'm having some success but I've one issue that's proved difficult to find in the archives. There are...
2
1756
by: Elliot | last post by:
After executing the following line: WB = XL.Workbooks.Open("c:\test.xls") Excel is visible using vb.net 2005. Is this a change from previous versions of VB? I know I can use xl.visible=false...
3
3228
by: saragoesnuts | last post by:
I have a program that automates to Excel with information in tables. I want to add charts to the excel file (pie charts, bar charts, etc). Is this possible?
3
1274
by: Cliff | last post by:
I'm attempting to automate input to an ASP/AJAX web-page using VBA, however, I've encountered a couple of problems: 1) when selecting from dropdown A manuallly, dropdown B is populated with a...
2
2610
by: nandishp | last post by:
We need to automate download of Reports from Oracle CRM OnDemand. The reports in Siebel CRM OnDemand can be downloaded in the form of Excel, CSV, etc. We have a task of downloading several such...
0
7057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5357
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1310
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.