How do I address a drive in VBA code

K

Kevin J Prince

How do I write code for a Word Template, which will include an AutoNew()
statement that opens a file, and writes to a file.
This template is to be shared over a network.

Cheers
 
P

Peter

Kevin J Prince said:
How do I write code for a Word Template, which will include an AutoNew()
statement that opens a file, and writes to a file.
This template is to be shared over a network.

Cheers

Two ways:

Use this code:

Open "my file.txt" For Output as #1
Write #1, "Hello World"
Close #1

Or

Open Tools | References
Scroll down to Microsoft Scripting Runtime
Check its corresponding checkbox.
OK your way out of the dialog.

Then use this code:

Dim oFS As New Scripting.FileSystemObject
Dim oTxt As Scripting.TextStream
oTxt = oFS.CreateTextFile("my text file.txt")
Call oTxt.WriteLine("Hello World")
Call oTxt.Close

For light use, I'd recommend the first way.

hth,

-Peter
 
K

Kevin J Prince

Peter
Thanks for the reply

Sadly it's not as simple as that...

The number.txt file contains a number in plain text. On the central
computer.
The template is on the central computer.
However the template has to run from each of 3 PC's on the network using
the same template and same number.txt file.

Method below opens the default drive for whatever PC's it 's on.

I have another Thread in this ng which has some code in it. And some
explanations... 'VB Local drive addressing'

In the other thread I explain that I can open the number.txt file from
any of the PC@s using the same template, but I can't save a file back on
any of the PC's using that method. (including the template host machine)

Regards

Kevin
 

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