Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 29, 2012 07:28 PM by Pravin8712
Apr 29, 2012 02:02 PM|LINK
Under my project, i have created a directory called "Tempaltes" and have put there several excel files I want to use later in my code. When working with those files, I want to use indirect paths. Let's say I want to open a file: \Templates\tempalte.xlsx
. How should I do that?
Dim fs = CreateObject("Scripting.FileSystemObject")
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkBook = xlApp.Workbooks.Open("/Templates/template.xlsx")
When doing that I get an error, that file /Templates/template.xlsx could not be found.
Of course everything works fine when I use direct paths to those files, but that makes the project less universal and causes potential issues when migrating to other platforms.
Apr 29, 2012 02:14 PM|LINK
xlWorkBook = xlApp.Workbooks.Open(Server.MapPath("~/Templates/template.xlsx"))
Apr 29, 2012 02:17 PM|LINK
I owe you a beer :) That's what I was looking for. Thanks a million Vipindas!
Apr 29, 2012 07:28 PM|LINK
use tild symbol at the start of your path like,