View Single Post
 
Old 12-15-2020, 05:14 PM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote