Sign in to follow this  
Followers 0
vanilla_gorilla

Little off topic :- VB form opening excel file

7 posts in this topic

This maybe a little off topic but figured I would try here. Im writing a VB front end to analyse data in a csv file (exported from excel), this data was collected and exported from a data logger I have installed on a machine and resides locally (or on the network) The user selects the file to "Analyse", by pushing a button on the "form". (after selecting the file through a standard windows interface) I want excel to open this file and from there I can analyse the data. (with code) I can get Excel to open (using "shell") but I cant get it to open the "user selected file" and make that worksheet the active sheet etc.. Was wondering if anyone could point me in the right direction. Incidentally I am using VB Express 2005.....

Share this post


Link to post
Share on other sites
I'm an old timer VB 6.0 still running great for me. Let me see if I get this right. 1. Your data logger exports data to files of type csv. So we have File001.csv, file002.csv, file003.csv and etc. 2. Using your VB front end form the user selects the file name he wants analyzed. have you registered the database objects and etc with Vb express. Using old vb 6 I'd open the file as a new excel object and be able to load any cell of it into a vb code variable. Can't speak as to VB Express 2005.

Share this post


Link to post
Share on other sites
The following code should work just fine. You will need to add a reference to the Microsoft Excel Object. Module OpenExcel Public Sub OpenCSV() Dim FilePath As String Dim GetFile As New Excel.Application GetFile.Visible = True GetFile.DisplayAlerts = False FilePath = "c:\MyFile.csv" GetFile.Workbooks.Open(FilePath) End Sub End Module Edited by TechJunki

Share this post


Link to post
Share on other sites
It sounds like you are trying to launch Excel instead of opening file by your application.

Share this post


Link to post
Share on other sites
Im opening a file that is a CSV from a button on a user form Once open I want to analyse some data and throw results back to text boxes on the form..... (Such as Start Time, Stop Time etc..) I can get excel to open no problem, I'm just having problems have it open with the "user selected" file they selected from the user form. open "user file in location X" with Excel, Once open look at cell X,Y and write that info to textbox2.txt etc.... Thx

Share this post


Link to post
Share on other sites
Have you tried the code that I posted, it will open a user defined file in excel just replace "c:\MyFile.csv" with whatever file the user has selected, I would use a listbox on the form to list all .csv files in a certain directory (or you could get "fancy" with a browse folders/files control) and have the user select the appropriate file then click an open button on the form launching the file. From this point manipulating the data is easy, but I think you need to get this portion straightened out first Edited by TechJunki

Share this post


Link to post
Share on other sites
VB 6 had constructs which mimiced my computer and windows explorer which you could add to VB forms and allow users to select files from within you app. There has also been API calls to get the windows window handle and file selectedfrom my explorer and pass this to VB. Did not go that way with VB6 ever , but know it can be done.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0