?
Solved

how to open a excel file in vb 6.0

Posted on 2003-03-25
8
Medium Priority
?
245 Views
Last Modified: 2010-05-01
Hi there,

does anyone know how i can handle the following problem?

In form1 I open my standard excel document (standard.XLS), put some new textlines in it and save it under another name (for example: Document1.XLS). So far so good... But in form2 I want to open the just saved file (Document1.XLS) by clicking on a command button , and again edit some textlines (out of textboxes in VB) and save it again as Document1.xls.

The next time I start my program I want to edit standard.XLS again and save it as document2.XLS or something like that open it in form2 etc, etc, etc.

Simply said:

The thing is that I always open the standard document but save it under another name. in form two i want to open the new made document for edit.

Who can help me?

thanks, Soontjes


0
Comment
Question by:soontjes1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8202487
not sure if this is what you are looking for,but shellexecute api will open anyfile with it's default app.

' declarations
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Private Sub Command1_Click()
ShellExecute hwnd, "Open", "C:\Somefile.xls", "", App.Path, 1
End Sub
0
 

Author Comment

by:soontjes1
ID: 8202666
Well cause i'm not must of a VBer i dont know how to place it in my code.. Do you? Here is a part of the code so far:

in the command button in form 1:

Private Sub Picture4_Click()
 Set xlApp = CreateObject("Excel.Application")
 
  name1 = "c:\documents and settings\Standaard.Xls"
 
 With xlApp
  .Workbooks.Open (name1)
 
  xlApp.Sheets(1).Cells(1, 2).Select
  xlApp.ActiveCell.Value = Text1.Text
 
 o = Val(Project.Text)
 
  xlApp.Sheets(1).Cells(7, 2).Select
  xlApp.ActiveCell.Value = o  
 
  xlApp.Sheets(1).Cells(5, 2).Select
  xlApp.ActiveCell.Value = Text3.Text

 End With
 
  name2 = "c:\documents and settings\VNr_" & Val(o) & ".XLS"
  xlApp.ActiveWorkbook.SaveAs FileName:=name2, FileFormat:=xlNormal, ReadOnlyRecommended:=False
  xlApp.DisplayAlerts = False
  xlApp.ActiveWorkbook.Close
  xlApp.Quit
 Set xlApp = Nothing

Now it is closed an saved under a new name.


In form 2 i want to open that file, but how must i implante your code then??

Thanks a lot!

0
 
LVL 11

Accepted Solution

by:
Steiner earned 60 total points
ID: 8203113
I'm not sure if I got your problem right, but why don't you just use a global variable for the document name?
How are form1 and form2 started? I guess they are in the same project and started one after another?
If that's so, create a module with the follwing line:
Public sWbName as String

In the line between "name2 = ..." and "xlApp.ActiveWorkbook.SaveAs" in form1 write
"sWbName=name2"

To open the same Excel file in Form2 use the same approach as you use in Form1, but instead of
name1="C:\documents and settings\standaard.xls"   use:
name1=sWbName
Also you'll have to modify your save routine, since you want to save it under the same name. So just use xlApp.ActiveWorkbook.Save.


So your code for form2 could look like:

Set xlApp = CreateObject("Excel.Application")

 name1 = sWbName

With xlApp
 .Workbooks.Open (name1)

 xlApp.Sheets(1).Cells(1, 2).Select
 xlApp.ActiveCell.Value = Text1.Text
 
o = Val(Project.Text)
 
 xlApp.Sheets(1).Cells(7, 2).Select
 xlApp.ActiveCell.Value = o  

 xlApp.Sheets(1).Cells(5, 2).Select
 xlApp.ActiveCell.Value = Text3.Text

End With

 xlApp.ActiveWorkbook.Save
 xlApp.DisplayAlerts = False
 xlApp.ActiveWorkbook.Close
 xlApp.Quit
Set xlApp = Nothing
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:soontjes1
ID: 8208748
Thanks, it works great!!!
0
 
LVL 11

Expert Comment

by:Steiner
ID: 8210483
So why grade B?
0
 
LVL 11

Expert Comment

by:Steiner
ID: 8215834
If you have a question to my solution, why didn't you post that here????
A grade B looks terrible in my profile...
0
 

Expert Comment

by:archekrypt
ID: 8216287
open it in a data control or connect to it through a provider, SQL, mySQL or just as a XLS!!!

cool!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question