![]() |
|
#2
|
||||
|
||||
|
There's nothing inherently 'wrong' with your code, though it could be made a little more efficient:
Code:
Sub Batch_Insert_Text_End_of_File()
Application.ScreenUpdating = False
Dim strInFold As String, strOutFold As String, strFile As String, strOutFile As String, DocSrc As Document
Dim i As Long
'Call the GetFolder Function to determine the folder to process
strInFold = GetFolder
If strInFold = "" Then Exit Sub
strFile = Dir(strInFold & "\*.txt", vbNormal)
'Check for documents in the folder - exit if none found
If strFile <> "" Then strOutFold = strInFold & "\Output\"
'Test for an existing outpfolder & create one if it doesn't already exist
If Dir(strOutFold, vbDirectory) = "" Then MkDir strOutFold
strFile = Dir(strInFold & "\*.txt", vbNormal)
'Process all documents in the chosen folder
While strFile <> ""
Set DocSrc = Documents.Open(FileName:=strInFold & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With DocSrc
i = i + 1 'counter for index
.Range.InsertAfter vbCrLf & _
" 45 CALCULATE, 'BLIN-ARRAY-SIZE' = XXX $" & vbCrLf & " 50 END, 'INIT_TABLE_" & i & "' $"
.SaveAs FileName:=strOutFold & .Name, FileFormat:=wdFormatText, AddToRecentFiles:=False
.Close
End With
strFile = Dir()
Wend
Set Rng = Nothing: Set DocSrc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder(Optional Title As String, Optional RootFolder As Variant) As String
On Error Resume Next
GetFolder = CreateObject("Shell.Application").BrowseForFolder(0, Title, 0, RootFolder).Items.Item.Path
End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
| Tags |
| batch file insert, slow response macro, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Remove Compatibility Mode on DOCX files (batch) | w64bit | Word | 17 | 02-01-2015 06:02 AM |
VBA Batch Find & Replace for all MSOffice extensions, to replace File Name and Content of the File
|
QA_Compliance_Advisor | Word VBA | 11 | 09-11-2014 11:51 PM |
how to batch update linked image files path?
|
stanleyhuang | Word | 3 | 09-11-2014 12:51 AM |
batch file
|
romanticbiro | Office | 1 | 06-30-2014 06:04 PM |
Insert-Text from File in Word Ribbon?
|
tatihulot | Word | 2 | 10-12-2011 04:40 AM |