Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default writing a text file in the same folder as my program

Could someone helps me?

I'm trying to write data on "TestData.txt", but place "TestData.txt" in the
same folder as my Excel program is placed.


Private Sub SaveThisSubInforGlobal()
Sheets("Response_2").Select

Open "TestData.txt" For Append As #1


Write #1, Cells(i, 1).Value; Cells(i, 2).Value; Cells(i, 3).Value

Close #1
End Sub


I find "TestData.txt" sometimes in the same folder as my Excel program is
placed, but also sometimes in "My Document." It is not consistent. Why is
this so? Is there any way I can place "TestData.txt" in the same folder as
my program is placed? I could do this easily with VB.6, but Excel VBA is
not consistent....


Thank you


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default writing a text file in the same folder as my program

Hi Takashi Yamauchi,

MsgBox Application.Path

but I don't consider it a good idea
to place data in the same location as the program's exe-file.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default writing a text file in the same folder as my program



Takashi Yamauchi wrote:
Is there any way I can place "TestData.txt" in the same folder as
my program is placed?


I don't know what is setting or varying the working directory in your
case. But here are some ideas so you can set it yourself right before
the write:

1. Assuming you want to set it to the directory of your .xls file you
can use ChDir Activeworkbook.path

2. If you really want to set it to the directory of the Excel
executable (excel.exe) you can use ChDir Application.path
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default writing a text file in the same folder as my program

If activeworkbook has not been saved, the curdir will be MyDocuments

Takashi Yamauchi wrote:
Could someone helps me?

I'm trying to write data on "TestData.txt", but place "TestData.txt" in the
same folder as my Excel program is placed.


Private Sub SaveThisSubInforGlobal()
Sheets("Response_2").Select

Open "TestData.txt" For Append As #1


Write #1, Cells(i, 1).Value; Cells(i, 2).Value; Cells(i, 3).Value

Close #1
End Sub


I find "TestData.txt" sometimes in the same folder as my Excel program is
placed, but also sometimes in "My Document." It is not consistent. Why is
this so? Is there any way I can place "TestData.txt" in the same folder as
my program is placed? I could do this easily with VB.6, but Excel VBA is
not consistent....


Thank you


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default writing a text file in the same folder as my program


wrote in message
...


Takashi Yamauchi wrote:
Is there any way I can place "TestData.txt" in the same folder as
my program is placed?


I don't know what is setting or varying the working directory in your
case. But here are some ideas so you can set it yourself right before
the write:

1. Assuming you want to set it to the directory of your .xls file you
can use ChDir Activeworkbook.path


Thank you. This worked, but only when I'm running the program from my main
hard disk. When I was running the program from a USB stick, the TestData.txt
is still placed in "My Document"....

But this is good enough.

Thank you again

takashi yamauchi


2. If you really want to set it to the directory of the Excel
executable (excel.exe) you can use ChDir Application.path



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing to text file ADK Excel Programming 7 July 13th 07 06:13 PM
Writing to a text file scantor145[_9_] Excel Programming 6 June 30th 05 08:23 PM
Writing to a text file Rachel Curran Excel Programming 0 October 8th 04 09:44 AM
Writing strings to a text file ? Dan Thompson Excel Programming 3 September 23rd 04 07:17 PM
Create Folder and Text File in folder Todd Huttentsine Excel Programming 2 April 29th 04 03:41 PM


All times are GMT +1. The time now is 01:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"