![]() |
|
|
|
#1
|
|||
|
|||
|
John,
It is all tied to when you initilize the userform. Try: Code:
Sub AllFolderDocs_Search()
Dim strFolder As String, strFile As String
Dim oFrm As Uform_PauseCode
Dim wdDoc As Document
Dim oRng As Range
Application.ScreenUpdating = False
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc*", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False)
With wdDoc
.Activate
Set oRng = .Range
With oRng.Find
.Text = "my search"
If .Execute Then
Application.ScreenUpdating = True
Set oFrm = New Uform_PauseCode
oFrm.Show vbModeless
Do
DoEvents
Loop
Application.ScreenUpdating = False
End If
End With
DoEvents
.Close SaveChanges:=True
End With
Set wdDoc = Nothing
strFile = Dir()
Wend
Application.ScreenUpdating = True
lbl_Exit:
Exit Sub
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
lbl_Exit:
Exit Function
End Function
|
|
#2
|
|||
|
|||
|
That's brilliant Greg - problem sorted
![]() I've read your help pages on Userforms should i should have suspected something like that. But the various 'Instances', methods of loading and unloading, calling, initializing and activating etc, is all fairly confusing for a relative beginner. Thank you |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Extract Document Property and insert it into the same document, for many files in a folder
|
MisrIdley | Word VBA | 1 | 12-07-2017 12:41 PM |
| VBA Word - Search Within Files Containing A String - Copy Files to New Folder | jc491 | Word VBA | 0 | 01-09-2016 12:00 PM |
| Outlook 2010: Saving attachments opens up wrong windows folder to save in | jeroen | Outlook | 0 | 09-29-2015 01:51 AM |
Music is attached to wrong animation
|
musbegin | PowerPoint | 2 | 11-17-2014 02:40 AM |
| VBA Code in a UserForm module to delete a Command Button which opens the userform | Simoninparis | Word VBA | 2 | 09-21-2014 03:50 AM |