PDA

View Full Version : Solved: Convert several word docs to text



RECrerar
12-04-2007, 04:58 AM
Hi THis is what I am looking to do.

1. Brouse to a folder and select multiple word documents
2. Select a folder to save these documents in
3. Convert the documents to text files and save in the selected folder.

I'm sure this is very simple but am really poor at word VBA and so am kinda stuck. I'm currently working on this so will continue trying for the solution and will post back with some basic code when I have some. In the mean time any pointers in the right direction would be appreciated.

RECrerar
12-04-2007, 05:34 AM
Hi Again. I now have most of the code I think, In that I can select the files and the save directory. The code sticks on the save as line. Can I save a file that I haven't opened if I have it's file name, and if so how?

Sub OpenFiles()

Set Fd = Application.FileDialog(msoFileDialogFilePicker)

' Select Files
With Fd
.AllowMultiSelect = True
.Show
B = .SelectedItems.Count
A = 1
If B = 0 Then Exit Sub
ReDim Files(1 To B) As String
For Each s In .SelectedItems
Files(A) = s
A = A + 1
Next
End With

' Chose Save location
GetDirectory.Show
End Sub

Sub SaveFiles()
For i = 1 To B
FileNm = Dir(Files(i))
A = Len(FileNm)
A = A - 4
FileNm = Left(FileNm, A) & ".txt"
ChangeFileOpenDirectory Directory
Documents(Files(i)).SaveAs Filename:=FileNm, FileFormat:=wdFormatText
Next i

End Sub

GetDirectory is a userform from the following thread, it defines the variable 'directory' and calls the SaveFiles sub.

the last line in the savefiles sub is the one that doesn't work.

Thanks in advance

RECrerar
12-04-2007, 05:47 AM
oops forgot to post the thread

http://www.vbaexpress.com/forum/showthread.php?t=15341

TonyJollans
12-04-2007, 10:59 AM
No you can't save a document you haven't opened.

RECrerar
12-05-2007, 02:42 AM
Thanks for the responce confirmation, have it working now.