Join 306,807 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,674 people online right now. Registration is fast and FREE... Join Now!
Hey Guys, My first topic/post and I'm new to these forums and I need help with spreadsheet, I need a tutorial or someone to help me with printing/saving/opening a spreadsheet. So far I've got no leads or anything and I've been searching for 2 days without any help. Is there a way to print a spreadsheet and save the spreadsheet and also open it? Thanks a lot much appreciated
Edit: Visual Basic 2008
This post has been edited by MuSSi: 5 Jun, 2009 - 06:37 PM
Public Class Form4 Private xlApp As New Excel.Application Private xlWBook As Excel.Workbook End Class
provided in the first link i get the following error:
CODE
Warning 1 Namespace or type specified in the Imports 'Microsoft.Office.Interop.Excel' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. C:\Documents and Settings\MuSSi\My Documents\Visual Studio 2008\Projects\Excel\Excel\Form4.vb 1 9 Excel
CODE
Warning 2 Namespace or type specified in the Imports 'Microsoft.Office.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. C:\Documents and Settings\MuSSi\My Documents\Visual Studio 2008\Projects\Excel\Excel\Form4.vb 2 9 Excel
Its not exactly what I needed but the template thing was. Is there a way to open the .xls file that i imported to the project ( e.g Form1.Show() ) I know its not as simple as that but is there something like that? Please Help Thanks
But instead of having App.StartupPath...etc... you'll want
CODE
Application.StartupPath & "\Filename.xls"
The Application.StartupPath is the bit that references your project's install directory.
For testing, copy the .xls file into the <Project>\bin\debug folder.
oBook and oExcel aren't declared. Is there a command such as Shell that will open a .xls file? Thats exactly what I'm trying to do but Shell only works with .exe
But instead of having App.StartupPath...etc... you'll want
CODE
Application.StartupPath & "\Filename.xls"
The Application.StartupPath is the bit that references your project's install directory.
For testing, copy the .xls file into the <Project>\bin\debug folder.
oBook and oExcel aren't declared. Is there a command such as Shell that will open a .xls file? Thats exactly what I'm trying to do but Shell only works with .exe
Edit: I tried OpenFileDialog1.Show() on a button click event but when i double clicked the .xls file it didnt do anything, is there a way to skip the dialog and just open the xls file at a certain directory not giving the user an option
This post has been edited by MuSSi: 9 Jun, 2009 - 08:25 PM
Were you not able to adapt to VB.Net the VBA example I presented in earlier post? Between that and Bort's terrific tutorial, you should have enough to accomplish this task. Perhaps if you posted your actual code for analysis we could be more helpful.
This post has been edited by June7: 9 Jun, 2009 - 11:47 PM
Imports System.IO Imports System.Globalization .......................................... Dim strFileName As String = Application.StartupPath & "\Data.xls" Dim proc As New Process proc.StartInfo.FileName = strFileName proc.StartInfo.Verb = "Print" proc.StartInfo.CreateNoWindow = True proc.Start()
Change the full path of file to suit
~'J'~
This post has been edited by fixo: 10 Jun, 2009 - 01:16 AM
Error 1 Type 'Excel.Application' is not defined. C:\Documents and Settings\MuSSi\My Documents\Visual Studio 2008\Projects\GTM\Excel\Form2.vb 5 30 Excel Error 2 Type 'Excel.Workbook' is not defined. C:\Documents and Settings\MuSSi\My Documents\Visual Studio 2008\Projects\GTM\Excel\Form2.vb 6 27 Excel Error 3 Name 'xlSheet' is not declared. C:\Documents and Settings\MuSSi\My Documents\Visual Studio 2008\Projects\GTM\Excel\Form2.vb 13 9 Excel Error 4 Name 'xlSheet' is not declared. C:\Documents and Settings\MuSSi\My Documents\Visual Studio 2008\Projects\GTM\Excel\Form2.vb 15 9 Excel
Sorry I'm new to all this, Just to be sure this is visual basic 2008 express edition right?
This post has been edited by MuSSi: 10 Jun, 2009 - 02:00 AM
This code is correct Mussi, and sorry, but my bad for not telling you this earlier...you missed the first part of my tutorial...
QUOTE
References
Before you can start automating any of the Office applications, you will need to add a reference to the application into your project. To do this, go to the Project menu, select Add Reference, and click on the COM tab. In the list, find the following entry:
Microsoft <App> Object Library <x>.0
Where <App> is the application you wish to automate, and <x> is the version number. For example, if I wanted to automate Word, it would be Microsoft Word Object Library 9.0. The version number depends on what version of Office you are using.
Office 2000 = version 9.0 Office XP = version 10.0 Office 2003 = version 11.0 Office 2007 = version 12.0.
Just to test why I'm getting all these errors I followed your tutorial added the reference Microsoft Word Object Library 11.0 and then did your code and came up with 2 errors, Type 'Word.Application' is not defined. Type 'Word.Document' is not defined. Please help?
(It would be alot more helpful if someone could add me on MSN at Mussy69a@live.com.au)
This post has been edited by MuSSi: 10 Jun, 2009 - 05:01 AM
When I wrote that tutorial, I was using old tech (VB2005 and Office 2000) so I think it may now be slightly out of date. At the very top of your code, before the Public Class Form2 line, put this:
CODE
Imports Excel = Microsoft.Office.Interop.Excel
and see if it helps
This post has been edited by Bort: 10 Jun, 2009 - 04:57 AM
Thanks that worked, I went back to see if I did anything wrong to June7s 1st post and saw that in a part of the script it uses WebBrowser1.Navigate to open the .xls file thats all I needed but thank you both. Bort could you please add me on MSN i'd like to learn a few things and I need help with 1 more thing