473,766 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ 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 "ComExcepti on 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 1320
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
1814
by: Nick Carter | last post by:
The following C# lines of code work fine with Excel 2000:- ExcelApplication excelApplication = new Excel.Application(); ExcelWorkbook excelWorkbook = excelApplication.Workbooks.Add(System.Reflection.Missing.Value); The second line fails when it is rebuilt with the Excel 97 type library and run on Excel 97. The error is an InteropServices.COMException and the message is "The server threw an exception" which is a bit too generic to give...
0
1440
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: ExcelSheet.Application.Worksheets("Sheet1").Range("D9:D12").Borders.Color = vbBlack but it puts a border around each cell in the range, not just around
22
15351
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 reproduce the behavior described below? For this example, I am using Excel 2002 and VS .NET 2002 and VB 6. MSFT KB article 304661 gives a trivial example of early and late binding to Excel from VB .NET. Note that there is a variable naming...
0
2116
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 it to another one it fails giving me the error: Additional information: Unable to set the HasMajorGridlines property of the Axis class Here is a excerpt of the code being run.
1
17957
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 a number of elements (ie. text boxes) on this web page that are conditionally "greyed out". They should become visible (ie. not greyed) when a prior element is entered with data. However, this is not happening. The elements are being filled,...
2
1773
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 after this line but it is a nuisance to have excel pop up even for a second when I don't use its interface. Thank you,
3
3252
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
1289
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 series of options depending on the option selected in drropdown A. While I can select from dropdown A in VBA, dropdown B never gets updated. Prsumably I need to trigger some event on the page, but how do I accomplish this in VBA? 2) clicking a...
2
2639
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 reports in Excel format everyday. The requirement is to automate the download of Reports by providing the URL of Excel format of report, Username and Password to logon to Oracle OnDemand. Using CSHttpUnit, we could logon to the OnDemand instance...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.