Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sardinka
Posting Yak Master
142 Posts |
Posted - 2005-08-25 : 09:17:09
|
How can I check if Excel file is exists and if doesn't create a new excel file? |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-25 : 09:24:41
|
This script will do thatCreate table #fileTest(FileExists int, Dir int, ParentDir int)Insert into #fileTest Exec master..xp_fileexist 'F:\test.xls' -- replace this by your File nameIf exists(select FileExists from #fileTest where FileExists=1) Print 'File Exists'else Print 'File does not Exist'Drop table #fileTest MadhivananFailing to plan is Planning to fail |
 |
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2005-08-25 : 10:50:02
|
I did the same using ActiveX, however I have 2 problems:1.When Excel is created it is created with 3 sheet which I wanted to delete (have no idea how)?2. When I do this: DROP TABLE Activity using Excel connection if table is not found it gives me an error. Is there is a way to check if table exists? |
 |
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-08-25 : 11:04:17
|
I have a code that copies a excel file from the template file, would that work for you ?Igor. |
 |
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2005-08-25 : 11:23:23
|
I am not sure that is what I am looking for, however can you submit your code, so I can take a look.Thanks |
 |
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-08-25 : 11:31:38
|
We have a folder with all templates for our reports and call those templates using the code below, you need to set up the template exactly how you setup the destination file.'**********************************************************************' Visual Basic ActiveX Script'************************************************************************Function Main()Dim fs Set fs = CreateObject("Scripting.FileSystemObject") destinationfilename = "C:\Test\Report.xls" if fs.fileexists(destinationfilename) then fs.deletefile destinationfilename templatefilename = "C:\Test\Template\Report.xls" if fs.fileexists(templatefilename) then fs.copyfile templatefilename, destinationfilename Main = DTSTaskExecResult_Success Main = DTSTaskExecResult_SuccessEnd FunctionIgor. |
 |
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2005-08-25 : 11:40:55
|
Thank you for the code, but I wanted create all files at run time instead of having a static folder with a templates. |
 |
|
|
|
|