Cannot access the file name urgent please

I have written the code like this but I got error in save method

error is "CANNOT ACCESS THE “EXPORTTOEXCEL.XLS”

pls guide me that how to solve the problem

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim ss As New NotesSession

Dim db As NotesDatabase

Dim vw As NotesView

Dim doc As NotesDocument

Dim item As NotesItem

Dim filepath As String, pathname As String

Dim filenum As Integer

Dim x As Variant, y As Variant

On Error Goto Errorhandle

Set uidoc=ws.CurrentDocument

Set db=ss.CurrentDatabase

Set vw=db.GetView(“Configuration”)

If vw Is Nothing Then Exit Sub

Set doc=vw.GetFirstDocument()

Set item= doc.GetFirstItem("ExcelfileName")

filepath=item.Text

filenum=Freefile()

’ Open Excel Application

If Len(Dir(filepath))>0 Then Kill filepath

Open filepath For Output As filenum

Set z=createobject(“Excel.Application”)

z.visible=True

z.caption=“Exporting From Notes Current Document to Excel”

z.worksheets(1).Name=“Customer Info”

z.worksheets(1).Range(“A1”).value=“Customer Details”

z.worksheets(1).Range(“A3”).value=" Name"

z.worksheets(1).Range(“B3”).value=“Email”

z.worksheets(1).Range(“C3”).value=“Phone”

z.worksheets(1).Range(“D3”).value=“City”

z.worksheets(1).Range(“E3”).value=“Address”

’ Export Data from Notes Document

i=2

Set x=z.Application.workbooks(1).worksheets(1)

If Not uidoc Is Nothing Then

Gosub Export

End If

If uidoc Is Nothing Then

Gosub Terminate

End If

’ Export Values from Out Door View

Export :

s=“A”+Cstr(3+i)+“:C”+Cstr(3+i)

x.cells(i+3,1).value=Cstr(uidoc.FieldGetText(“CuName”)) ’ Item

x.cells(i+3,2).value=Cstr(uidoc.FieldGetText(“CuEmail”)) ’ Item

x.cells(i+3,3).value=Cstr(uidoc.FieldGetText(“CuPhone”)) ’ Item

x.cells(i+3,4).value=Cstr(uidoc.FieldGetText(“CuCity”)) 'item

x.cells(i+3,5).value=Cstr(uidoc.FieldGetText(“CuAddress”))'Item

'Set x=Nothing

Set y=z.ActiveWorkbook

Call y.SaveAs(filepath) //I GOT THE ERROR HERE

Call y.close

z.Quit

Set z=Nothing

Close filenum

Terminate :

Exit Sub

Errorhandle:

Messagebox “Error:” & Error & " at line " & Cstr(Erl)

End Sub

with hope

thanks and regards

Subject: Cannot access the file name urgent please

Never hurts to give more information.

Where are you writing the file to? A network drive your Hard drive? Is your hard drive full? You’re not sure?

Here is what I would suggest:

  • Write the file to the root of your c drive - then you have no security issues.

  • Use a shorter file name. In the good ole days file names were 8 characters with a 3 character extension. Just incase you’re running into something weird give it a simple file name to start - mytest.xls

  • If your file name includes a path step through the debugger to make sure the path is not losing the ""'s you may need extra 's depending upon how you set them. c:\mytest.xls

  • Does the file already exist? If so, try it once without a file that already exist to see if it’s the existance it has a problem with.

  • If the file already exist - is it possibly the fact it works fine if NO one has the file open but there is a problem if someone else (or you) have the file open?

Lots of questions No information.

Subject: Cannot access the file name urgent please

Hi,

Check out if there are any folder access rights.

HTH…Gov.

Subject: RE: Cannot access the file name urgent please

Excel cannot save to the file because the file is in use (sharing violation). The file is in use because you opened it with the statement Open filepath For Output As filenum. Why did you do that? Don’t do that.