Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 12th, 2003, 09:39 PM
jbelmira jbelmira is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Elmira, Ontario
Posts: 16 jbelmira User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Excel file created in VB won't open in Excel

I have created a file in VB that writes numbers and formulas etc into an excel file. If I do not set the visible property of the file to false, I can see all the data successfully going into Excel. I can retrieve the results of a formula I have written into a cell. When I save the file from VB, it is totally unuseable when I open it in Excel. Can you shed some light on what I need to do to make the file available from Excel? Thanks.

Reply With Quote
  #2  
Old November 13th, 2003, 12:45 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
I haven't know the whole meaning!Would u write or save the excel file when u are reading it at the same time??

Reply With Quote
  #3  
Old November 13th, 2003, 08:18 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
well, what do you mean the file is "completely unusable"? Can you open the file at all? If you can...is there anything in it? Can you post some code so we can see what you're doing?
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #4  
Old November 13th, 2003, 08:37 PM
jbelmira jbelmira is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Elmira, Ontario
Posts: 16 jbelmira User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry for the lack of detail. I've written some code to create an Excel file from VB. When I issue the Application.Save method, my Excel file saves, yet there is nothing in it when I try opening it inside Excel. Here is my code. The objects that I used are self explanatory.

Option Explicit
Dim objExcel As Object


Private Sub cmdCalculate_Click()
Set objExcel = CreateObject("excel.sheet")
objExcel.Application.Visible = True

Rem Fill in the row labels.
objExcel.Application.Cells(1, 1).Value = "Tuition and Fees"
objExcel.Application.Cells(2, 1).Value = "Books and Supplies"
objExcel.Application.Cells(3, 1).Value = "Board"
objExcel.Application.Cells(4, 1).Value = "Transportation"
objExcel.Application.Cells(5, 1).Value = "Other Expenses"
objExcel.Application.Cells(7, 1).Value = "Total"

Rem Fill in the values
objExcel.Application.Cells(1, 3).Value = Text1.Text
objExcel.Application.Cells(2, 3).Value = Text2.Text
objExcel.Application.Cells(3, 3).Value = Text3.Text
objExcel.Application.Cells(4, 3).Value = Text4.Text
objExcel.Application.Cells(5, 3).Value = Text5.Text
objExcel.Application.Cells(7, 3).Formula = "=sum(c1:c5)"
objExcel.Application.Cells(7, 3).Font.Bold = True

Text6.Text = objExcel.Application.Cells(7, 3).Value

'objExcel.Application.Visible = False

End Sub

Private Sub cmdSave_Click()
objExcel.Application.Save App.Path & "\Expenses.xls"
End Sub

Private Sub cmdQuit_Click()
objExcel.Application.Quit
Set objExcel = Nothing
End
End Sub

I hope some of you can detect where my code is lacking. Also, is there a resource I can use to find the various properties and methods I need to be able to use in order to edit my Excel file from VB?

Thanks in advance.
me

Reply With Quote
  #5  
Old November 14th, 2003, 09:03 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
U don't close the objExcel.Application!!..

Reply With Quote
  #6  
Old November 14th, 2003, 11:38 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
a question - are you writing this in ASP, VBScript, or VB? if so, try using the set objExcel = new excel.application syntax instead of ("CreateObject").

Reply With Quote
  #7  
Old November 15th, 2003, 11:04 PM
jbelmira jbelmira is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Elmira, Ontario
Posts: 16 jbelmira User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This code is running in VB.
Your suggestion makes sense.
The set objExcel = new excel.application is accepted, yet the program generates an error on the first objExcel.Application.Cells statement following it. The error is:
Application defined or object defined error.

I just can't seem to find much documentation to refer to regarding connecting to Excel and creating a new file (that I am able to open in Excel later.

Reply With Quote
  #8  
Old November 16th, 2003, 07:43 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
You need to reference the Microsoft Excel Object Library. (Choose
"references" in VB or Access.) Then dimension a workbook like this:

dim xlb as Excel.workbook

Then:


set xlb = Workbooks.Open(filname)


Give it a try.

Reply With Quote
  #9  
Old November 22nd, 2003, 04:36 AM
Hermits-cave Hermits-cave is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 1 Hermits-cave User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Excel file created in VB won't open in Excel

Try this :--

Option Explicit
Dim objExcel As Object ' Excel application
Dim objBook As Object ' Excel workbook
Dim objSheet As Object ' Excel Worksheet



Private Sub cmdCalculate_Click()

Set objExcel = CreateObject("excel.application") 'Starts the Excel Session
Set objBook = objExcel.Workbooks.Add 'Add a Workbook
Set objSheet = objBook.Worksheets.Item(1) 'Select a Sheet
objExcel.application.Visible = True

Rem Fill in the row labels.
objExcel.application.Cells(1, 1).Value = "Tuition and Fees"
objExcel.application.Cells(2, 1).Value = "Books and Supplies"
objExcel.application.Cells(3, 1).Value = "Board"
objExcel.application.Cells(4, 1).Value = "Transportation"
objExcel.application.Cells(5, 1).Value = "Other Expenses"
objExcel.application.Cells(7, 1).Value = "Total"

Rem Fill in the values
objExcel.application.Cells(1, 3).Value = Text1.Text
objExcel.application.Cells(2, 3).Value = Text2.Text
objExcel.application.Cells(3, 3).Value = Text3.Text
objExcel.application.Cells(4, 3).Value = Text4.Text
objExcel.application.Cells(5, 3).Value = Text5.Text
objExcel.application.Cells(7, 3).Formula = "=sum(c1:c5)"
objExcel.application.Cells(7, 3).Font.Bold = True

Text6.Text = objExcel.application.Cells(7, 3).Value

'objExcel.Application.Visible = False

End Sub

Private Sub cmdSave_Click()
objBook.SaveAs "c:\expenses.xls"
objBook.Close
objExcel.Quit
Set objSheet = Nothing
Set objBook = Nothing
Set objExcel = Nothing

End Sub

Private Sub cmdQuit_Click()
Set objExcel = Nothing
End
End Sub


This method works no problem. The reason why yours will not open is that you are saving a session of excel as "expenses" as oposed to the workbook or sheet.

Hope this helps

Reply With Quote
  #10  
Old December 17th, 2003, 02:23 AM
aykurt aykurt is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 aykurt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to aykurt
Unhappy Automating EXCEL from Visual Basic

Hi there,

I've tried the codes examples above, but when i try to execute the examples I've get an error message.

Microsoft Development Environment

An unhandled exception of type
'System.RunTime.InteropServices.COMException' occured in example.exe

Additional information: Old format or invalid type Library

I am using Windows 2000, Visual Basic .NET og Office XP

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Excel file created in VB won't open in Excel


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway