Opening directory/file

B

Bernd Kuegle

Hi!

I am using a little VBA programm in Excel to open a certain directory/file.
I wanted to use the same programm in Word but it dosn´t work. Who can help?

ChDrive "G:\"
ChDir "G:\DATES\"
o_dir = Application.GetOpenFilename("Winword.exe (*.*), *.*")
Workbooks.Open FileName:=o_dir

Bernd
 
J

Jonathan West

Bernd Kuegle said:
Hi!

I am using a little VBA programm in Excel to open a certain
directory/file.
I wanted to use the same programm in Word but it dosn´t work. Who can
help?

ChDrive "G:\"
ChDir "G:\DATES\"
o_dir = Application.GetOpenFilename("Winword.exe (*.*), *.*")
Workbooks.Open FileName:=o_dir

Bernd

Hi Bernd

Try this

With Dialogs(wdDialogFileOpen)
.name = "G:\DATES\"
.Show
End With
 
C

Chuck

Hi Bernd

"GetOpenFilename" doesn't seem to be a valid Word VBA command.

In order to use Workbooks.Open in Word you'd have to use it with a valid
Excel object.

In any case it's unclear what file you're trying to open. Your code
suggests you're trying to open every file in the G:\Dates directory in its
own instance of Word.

If you're trying to open a specific file then
Documents.Open("c:\yourfile.doc") should work.

If you're trying to open all the docs in a directory, perform some actions
on them and close them then you can use FileSearch as fiollows:

Dim intPos As Long

With Application.FileSearch
.FileName = "*.doc"
.LookIn = "G:\DATES"
.Execute
For i = 1 To .FoundFiles.Count
intPos = InStr(1, _
CStr(.FoundFiles(i)), "~") 'ignore hidden files
If intPos > 0 Then
'do nothing
Else
If Not FileLocked(.FoundFiles(i)) Then
Documents.Open .FoundFiles(i)
'do stuff with your file here
.Close savechanges:=wdSaveChanges
End If
End If
Next i
End With

If you want to open all the docs in a directory and leave them open, delete
the .Close line in the code above.

HTH
Chuck
 

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