Results 1 to 5 of 5

Thread: What am I missing with opening excel

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    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:
    1. Public Sub Ammunition_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ammunition.Click
    2.  
    3.         Dim objExcel As Excel.Application
    4.         Dim objWorkBook As Excel.Workbook
    5.         objExcel = New Excel.Application
    6.         objWorkBook = objExcel.Workbooks.Open("c:\program files\rsdb\files\ammunitionreq.xls")
    7.         objExcel.Visible = True
    8.         objWorkBook = Nothing
    9.         objExcel = Nothing
    10.     End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683
    I figured it out. What I was looking for was Application.StartupPath.ToString

  3. #3
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683
    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.

  5. #5
    Registered User NicoNel2000's Avatar
    Join Date
    Feb 2004
    Location
    Beijing - China
    Posts
    296
    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
  •  



Click Here to Expand Forum to Full Width