Outlook Script: How to create / delete txt file

B

bbnimda

Hi all,

I use custom form and I want to know how to manipulate simple file *.txt

I need 3 operations
1) check if xxx.txt exist
2) delete xxx.txt
3) save the content of listbox to xxx.txt

2nd step
load the content of xxx.txt to a listbox


tks
--
 
E

Eric Legault [MVP - Outlook]

You can use the VBA.FileSystem.Dir function to check for the existence of a
file and VBA.FileSystem.Kill to delete files.

Here's a sample for reading from a file:

Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file for reading.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Read next character of data.
Debug.Print Seek(1) ' Print byte position to the
' Immediate window.
Loop
Close #1 ' Close file.

The Microsoft Scripting Library has a FileSystemObject class that can also
be used for file operations.
 
B

bbnimda

It doesnt work

but I tryed FileSystemObject and found the way to Check if file exist
and delete it

here is my code
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objfso.FileExists("C:\FSO\FileT.txt") then
objfso.DeleteFile "C:\FSO\FileT.txt"
else
.....
.....
.....
end if

But I still looking for a way to Create a new file and fill it and Save
it
 
E

Eric Legault [MVP - Outlook]

Did you change "TESTFILE" to a valid file path?

You can also create a file with the FileSystemObject:

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 
B

bbnimda

Yes I all ready found "CreateTextFile" but still was looking for the way
to fill the file ( tks for Writeline )

Ok now I know how to create , fill and save a text file

Now I have to open an existing text file and get data from this file

Tks for help




Eric Legault said:
Did you change "TESTFILE" to a valid file path?

You can also create a file with the FileSystemObject:

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


bbnimda said:
It doesnt work

but I tryed FileSystemObject and found the way to Check if file exist
and delete it

here is my code
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objfso.FileExists("C:\FSO\FileT.txt") then
objfso.DeleteFile "C:\FSO\FileT.txt"
else
.....
.....
.....
end if

But I still looking for a way to Create a new file and fill it and
Save
it



"Eric Legault [MVP - Outlook]" <[email protected]> a écrit
dans
le message de news: (e-mail address removed)...
You can use the VBA.FileSystem.Dir function to check for the existence
of
a
file and VBA.FileSystem.Kill to delete files.

Here's a sample for reading from a file:

Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file for reading.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Read next character of data.
Debug.Print Seek(1) ' Print byte position to the
' Immediate window.
Loop
Close #1 ' Close file.

The Microsoft Scripting Library has a FileSystemObject class that can
also
be used for file operations.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


:

Hi all,

I use custom form and I want to know how to manipulate simple file
*.txt

I need 3 operations
1) check if xxx.txt exist
2) delete xxx.txt
3) save the content of listbox to xxx.txt

2nd step
load the content of xxx.txt to a listbox


tks
 
E

Eric Legault [MVP - Outlook]

This might come in handy:

VBScript Language Reference:
http://msdn2.microsoft.com/en-us/library/d1wf56tt.aspx

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


bbnimda said:
Yes I all ready found "CreateTextFile" but still was looking for the way
to fill the file ( tks for Writeline )

Ok now I know how to create , fill and save a text file

Now I have to open an existing text file and get data from this file

Tks for help




Eric Legault said:
Did you change "TESTFILE" to a valid file path?

You can also create a file with the FileSystemObject:

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


bbnimda said:
It doesnt work

but I tryed FileSystemObject and found the way to Check if file exist
and delete it

here is my code
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objfso.FileExists("C:\FSO\FileT.txt") then
objfso.DeleteFile "C:\FSO\FileT.txt"
else
.....
.....
.....
end if

But I still looking for a way to Create a new file and fill it and
Save
it



"Eric Legault [MVP - Outlook]" <[email protected]> a écrit
dans
le message de news: (e-mail address removed)...
You can use the VBA.FileSystem.Dir function to check for the existence
of
a
file and VBA.FileSystem.Kill to delete files.

Here's a sample for reading from a file:

Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file for reading.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Read next character of data.
Debug.Print Seek(1) ' Print byte position to the
' Immediate window.
Loop
Close #1 ' Close file.

The Microsoft Scripting Library has a FileSystemObject class that can
also
be used for file operations.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


:

Hi all,

I use custom form and I want to know how to manipulate simple file
*.txt

I need 3 operations
1) check if xxx.txt exist
2) delete xxx.txt
3) save the content of listbox to xxx.txt

2nd step
load the content of xxx.txt to a listbox


tks
 
B

bbnimda

Tks a lot Eric,

Now my form is working perfectly

Bye

Eric Legault said:
This might come in handy:

VBScript Language Reference:
http://msdn2.microsoft.com/en-us/library/d1wf56tt.aspx

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


bbnimda said:
Yes I all ready found "CreateTextFile" but still was looking for the
way
to fill the file ( tks for Writeline )

Ok now I know how to create , fill and save a text file

Now I have to open an existing text file and get data from this file

Tks for help




"Eric Legault [MVP - Outlook]" <[email protected]> a écrit
dans
le message de news: (e-mail address removed)...
Did you change "TESTFILE" to a valid file path?

You can also create a file with the FileSystemObject:

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


:

It doesnt work

but I tryed FileSystemObject and found the way to Check if file
exist
and delete it

here is my code
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objfso.FileExists("C:\FSO\FileT.txt") then
objfso.DeleteFile "C:\FSO\FileT.txt"
else
.....
.....
.....
end if

But I still looking for a way to Create a new file and fill it and
Save
it



"Eric Legault [MVP - Outlook]" <[email protected]> a écrit
dans
le message de (e-mail address removed)...
You can use the VBA.FileSystem.Dir function to check for the
existence
of
a
file and VBA.FileSystem.Kill to delete files.

Here's a sample for reading from a file:

Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file for reading.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Read next character of data.
Debug.Print Seek(1) ' Print byte position to the
' Immediate window.
Loop
Close #1 ' Close file.

The Microsoft Scripting Library has a FileSystemObject class that
can
also
be used for file operations.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming,
etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


:

Hi all,

I use custom form and I want to know how to manipulate simple file
*.txt

I need 3 operations
1) check if xxx.txt exist
2) delete xxx.txt
3) save the content of listbox to xxx.txt

2nd step
load the content of xxx.txt to a listbox


tks
 

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