VBA and opening a text file

A

Amit

Hello group,

I'm using the follownig command in VBA code. This VBA code is used in
Excel and placed in startup directory which gets started as soon as
Excel is opened. But I get 'permission denied" error number 70 when
it the execution reaches here!

However, in normal way when I open it by Excel (no start up) it works
fine. Would you pleaes advice me on this?

Thanks,
AK


Open strLogFileName For Output As #FileNum
 
S

Steve Rindsberg

Hello group,

I'm using the follownig command in VBA code. This VBA code is used in
Excel and placed in startup directory which gets started as soon as
Excel is opened. But I get 'permission denied" error number 70 when
it the execution reaches here!

However, in normal way when I open it by Excel (no start up) it works
fine. Would you pleaes advice me on this?

Thanks,
AK

Open strLogFileName For Output As #FileNum

That's not enough code to go on. As it stands, it works, assuming everything
else is ok. And clearly it's not.
 
E

Edvado

Amit said:
Hello group,

I'm using the follownig command in VBA code. This VBA code is used in
Excel and placed in startup directory which gets started as soon as
Excel is opened. But I get 'permission denied" error number 70 when
it the execution reaches here!

However, in normal way when I open it by Excel (no start up) it works
fine. Would you pleaes advice me on this?

Thanks,
AK


Open strLogFileName For Output As #FileNum

Two things come to mind:
1) Is the file already open, maybe by another application?
2) Have you been careful in the use of that FileNum? It must be closed
before you try to open it. You might want to try programatically
closing it before you try to open it.
 
P

Perry

Use function FreeFile() to assign a value to variable FileNum

Dim FileNum as integer
FileNum = FreeFile()
Open strLogFileName For Output As #FileNum
....etc

Pls repost, if this doesn't work.

Krgrds,
Perry
 
A

Amit

Hi guys,

thanks for your help. Yes now it is working. I used to create and use
them in /program files/Myapp directory but it seems the proper way is
to use them in local directories that since during run time Windows
doesn't give me permission to write into file located in above path. So
I used Document and Settings/Myusername/Applicationd Data/MyApp
directory.

Thanks for your help.
ak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top