|
-
Aug 24th, 2004, 01:24 PM
#1
Thread Starter
Fanatic Member
What am I missing with opening excel
If I hard code the directory of where my xls file is it works. I want to be able to have it grab the file whereever the program was installed because users will do that to ya, so hardcoding will not work. This line - objWorkBook = objExcel.Workbooks.Open("c:\program files\rsdb\files\ammunitionreq.xls") is the one I want to make dynamic. Something like ..files/ammunitionreq.xls. Here is the bit of code that opens the file
VB Code:
Public Sub Ammunition_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ammunition.Click
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
objExcel = New Excel.Application
objWorkBook = objExcel.Workbooks.Open("c:\program files\rsdb\files\ammunitionreq.xls")
objExcel.Visible = True
objWorkBook = Nothing
objExcel = Nothing
End Sub
-
Aug 24th, 2004, 02:14 PM
#2
Thread Starter
Fanatic Member
I figured it out. What I was looking for was Application.StartupPath.ToString
-
Aug 25th, 2004, 06:58 AM
#3
Hyperactive Member
I have a question for you.
Why are you opening an instance of Excel?
Is it simply to read data from the sheet?
If so, there is a better way.
Whadayamean it doesn't work....
It works fine on my machine!

-
Aug 25th, 2004, 07:20 AM
#4
Thread Starter
Fanatic Member
I am opening excel because the users use this sheet for bookings. It has many colors to it and they need to edit it. I have tried (in vb6) to import it into a grid but have not been able to get the same functionality as excel, I truly wish I could. If you have any ideas on how to do this, please let me know. Also, can you please let me know what your better way is. I do many apps for different areas at our work and excel is by far not one of my favourites to have added.
-
Aug 25th, 2004, 07:31 AM
#5
Registered User
If your only purpose is to open the workbook for the user (meaning you don't want to work with it further in code), try this:
Process.Start(filepath) .. where file path is some the full physical path of the file.
I only found out bout this, this morning, so any critic or feedback on this one is welcome!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|