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.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Excel

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 that


Create table #fileTest(FileExists int, Dir int, ParentDir int)
Insert into #fileTest Exec master..xp_fileexist 'F:\test.xls' -- replace this by your File name
If exists(select FileExists from #fileTest where FileExists=1)
Print 'File Exists'
else
Print 'File does not Exist'
Drop table #fileTest


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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?
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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_Success
End Function


Igor.
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -