Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2011, 02:31 AM
bolk bolk is offline looking for macro for multiple files Windows XP looking for macro for multiple files Office 2003
Novice
looking for macro for multiple files
 
Join Date: May 2011
Posts: 2
bolk is on a distinguished road
Default looking for macro for multiple files

I made a macro to do conversions on a file.



Now i have 150+ files in a folder to convert using Word (2003).
Can anyboy help me to run my macro as long as there are unconverted files in my folder?

TIA,

Rutger
Reply With Quote
  #2  
Old 05-03-2011, 02:48 AM
macropod's Avatar
macropod macropod is offline looking for macro for multiple files Windows 7 32bit looking for macro for multiple files Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Rutger,

What constitutes an unconverted file vs a converted file? Apart from that, the basic code for selecting a folder and looping through the Word documents in it is:
Code:
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 <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      'Do something
      .Close SaveChanges:=True
    End With
  End If
  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
When you run the 'UpdateDocuments' macro, the 'GetFolder' function opens up a dialogue box for navigating to the folder of interest. The 'UpdateDocuments' macro then processes the documents in that folder. The code for whatever you're doing with each file goes where indicated.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-03-2011, 05:23 AM
bolk bolk is offline looking for macro for multiple files Windows XP looking for macro for multiple files Office 2003
Novice
looking for macro for multiple files
 
Join Date: May 2011
Posts: 2
bolk is on a distinguished road
Default

Thanks a lot! This is exactly what I was looking for.
The only problem I have is now to save the documents, somehow they are not.
I guess because the documents are .prn text files.

Rutger
Reply With Quote
  #4  
Old 05-03-2011, 05:46 AM
macropod's Avatar
macropod macropod is offline looking for macro for multiple files Windows 7 32bit looking for macro for multiple files Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Rutger

If you're opening .txt files, obviously you'd have to specify that as the type to find & open. To then save them in the Word document format, you'd need to use the SaveAs method.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro vba word

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
looking for macro for multiple files Need macro to merge files in Word and preserve formatting Carolin Word VBA 3 12-14-2014 04:01 AM
Multiple PPT files in different windows? Caroline PowerPoint 0 04-11-2011 09:40 AM
looking for macro for multiple files macro to pull data from multiple files psrs0810 Excel 2 10-25-2010 01:49 PM
Merging Multiple Word files into One Stattovic Word 0 01-06-2010 07:19 AM
Help-overwriting files-could it be macro virus? Timpotty Word 0 03-06-2009 04:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft