Results 1 to 2 of 2

Thread: Excel file location

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    19

    Exclamation Excel file location

    how do u point the code to your excel sheet?

    Code:
           objApp = New Excel.Application
            objBooks = objApp.Workbooks
            objBook = objBooks.Add
            objsheets = objBook.Worksheets
            objsheet = objsheets(1)
    
            objBooks = CreateObject("Excel.Application")
    something like application.startuppath???

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Excel file location

    You have to pass the path of the file to to the Workbooks.Open method. If your file is in your program folder then you can use Application.StartupPath to build that path. Application.StartupPath is just a property and it retruns a string containing the path to the folder from which the current application was run. If you want to get the path to the file Workbook.xls in your program folder then use:
    VB Code:
    1. Dim filePath As String = IO.Path.Combine(Application.StartupPath, "Workbook.xls")
    If your app was run from "C:\Program Files\MyApp" then filePath will contain "C:\Program Files\MyApp\Workbook.xls".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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