PDA

View Full Version : Macro to run a macro in sub Folders



Rakesh
10-09-2010, 02:49 AM
Hi,

I Had Folder with subfolders contains as much of Word Documents.

I had a macro file.

I have to run the macro for each and every Word Documents and to save as the file with the same name as Plain Text Format.

Is there is any Coding already created to do this.

Thanks,
Rakesh

Sebastian H
10-21-2010, 05:19 PM
There is an example in the on line help, at Dir Function Example. You can get there by entering Dir then hitting the F1 key and then clicking on the link to Example. The last example on that page is similar to what you need, except that you want to search for files that are not directories.

Tinbendr
10-21-2010, 06:00 PM
Here's a knowledge base entry for processing all files (http://www.vbaexpress.com/kb/getarticle.php?kb_id=245).

At top of Sub ProcessFiles, Add
Dim aDoc as Document Then add
'Do things with files here*****************
Set aDoc = Documents.Open(strFileName, Visible:=False)
aDoc.SaveAs Left(strFileName, InStr(strFileName, ".")-1), wdFormatDOSTextLineBreaks
aDoc.Close


(Note 2010 is SaveAs2)

Rakesh
03-18-2012, 12:34 PM
There is an example in the on line help, at Dir Function Example. You can get there by entering Dir then hitting the F1 key and then clicking on the link to Example. The last example on that page is similar to what you need, except that you want to search for files that are not directories.

Hi,

I am using Macinthosh System. Where do I get Online Help?

Thanks

macropod
03-18-2012, 04:31 PM
I am using Macinthosh System. Where do I get Online Help?
Online ...

Some sites you might want to check are:
http://mac2.microsoft.com/help/office/14/en-us/word/
http://mac2.microsoft.com/help/office/14/en-us/word/item/bb539409-4be8-48da-a1b3-842cf958fffb
http://answers.microsoft.com/en-us/mac

Rakesh
03-21-2012, 12:11 PM
Hi macropod,

I gone through the link. But I have not catched anything what I am looking for. Closer to need I got the coding is below but it shows compile error.

Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
'Do something
End With
wdDoc.Close SaveChanges:=True
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Thanks,
Rakesh

macropod
03-21-2012, 02:44 PM
Hi Rakesh,

When posting code, please use the VBA tags, so that the code gets properly formatted. You've seen plenty of code that I've posted in your other threads that use them.

Your code looks like it might have been copied from some that I've posted. It's for a PC - not for a Mac - and I don't know what would need changing to make it run on a Mac.

Frosty
03-22-2012, 04:55 PM
One place to start is to use Application.PathSeparator rather than the "\" character... that will use whatever it is that the Mac uses.

Apart from that, I'm not sure either.