Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-25-2017, 10:10 AM
Jude24Joy Jude24Joy is offline Combining 3 Modules into 1 Windows 8 Combining 3 Modules into 1 Office 2013
Novice
Combining 3 Modules into 1
 
Join Date: Dec 2016
Posts: 15
Jude24Joy is on a distinguished road
Default Combining 3 Modules into 1


Hello!

I have 3 modules that I run on .doc* files in succession. I would love to be able to run them all at once. For the first two, I select files in a folder, and for the third, I select the folder itself. Either method would be fine.

The first two modules are actually the same, but the find/replace text is different. The third module removes author information and hyperlinks.

I'm going to copy them here.

Can these be combined in some way?

Thanks in advance!


First module:

Code:
Sub CommandButton1_Click() 
Dim MyDialog As FileDialog, GetStr(1 To 300) As String '300 files is the maximum applying this code
On Error Resume Next 
Set MyDialog = Application.FileDialog(msoFileDialogFilePicker) 
With MyDialog 
  .Filters.Clear 
  .Filters.Add "All WORD File ", "*.doc*", 1 
  .AllowMultiSelect = True 
  i = 1 
  If .Show = -1 Then 
    For Each stiSelectedItem In .SelectedItems 
      GetStr(i) = stiSelectedItem 
      i = i + 1 
    Next 
    i = i - 1 
  End If 
  Application.ScreenUpdating = False 
  For j = 1 To i Step 1 
    Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True) 
    Windows(GetStr(j)).Activate 
    Selection.Find.ClearFormatting 
    Selection.Find.Replacement.ClearFormatting 
    With Selection.Find 
      .Text = "[text to replace here 1]" 
      .Replacement.Text = "[replacement text here 1]" 
      .Forward = True 
      .Wrap = wdFindAsk 
      .Format = False 
      .MatchCase = False 
      .MatchWholeWord = False 
      .MatchByte = True 
      .MatchWildcards = False 
      .MatchSoundsLike = False 
      .MatchAllWordForms = False 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
    Application.Run macroname:="NEWMACROS" 
    ActiveDocument.Save 
    ActiveWindow.Close 
  Next 
  Application.ScreenUpdating = True 
End With 
MsgBox "operation end, please view", vbInformation 
End Sub
Module 2:
Code:
Sub CommandButton2_Click() 
Dim MyDialog As FileDialog, GetStr(1 To 300) As String '300 files is the maximum applying this code
On Error Resume Next 
Set MyDialog = Application.FileDialog(msoFileDialogFilePicker) 
With MyDialog 
  .Filters.Clear 
  .Filters.Add "All WORD File ", "*.doc*", 1 
  .AllowMultiSelect = True 
  i = 1 
  If .Show = -1 Then 
    For Each stiSelectedItem In .SelectedItems 
      GetStr(i) = stiSelectedItem 
      i = i + 1 
    Next 
    i = i - 1 
  End If 
  Application.ScreenUpdating = False 
  For j = 1 To i Step 1 
    Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True) 
    Windows(GetStr(j)).Activate 
    Selection.Find.ClearFormatting 
    Selection.Find.Replacement.ClearFormatting 
    With Selection.Find 
      .Text = "[text to replace here 2]" 
      .Replacement.Text = "[replacement text here 2]" 
      .Forward = True 
      .Wrap = wdFindAsk 
      .Format = False 
      .MatchCase = False 
      .MatchWholeWord = False 
      .MatchByte = True 
      .MatchWildcards = True 
      .MatchSoundsLike = False 
      .MatchAllWordForms = False 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
    Application.Run macroname:="NEWMACROS" 
    ActiveDocument.Save 
    ActiveWindow.Close 
  Next 
  Application.ScreenUpdating = True 
End With 
MsgBox "operation end, please view", vbInformation 
End Sub
Module 3:
Code:
Sub UpdateDocuments() 
Application.ScreenUpdating = False 
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document 
strDocNm = ActiveDocument.FullName 
strFolder = GetFolder 
If strFolder = "" Then Exit Sub 
strFile = Dir(strFolder & "\*.doc") 
While strFile <> "" 
  If strFolder & "\" & strFile <> strDocNm Then 
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) 
    With wdDoc 
      .Fields.Unlink 
      .RemoveDocumentInformation (wdRDIAll) 
      .Close SaveChanges:=True 
    End With 
  End If 
  strFile = Dir() 
Wend 
Set wdDoc = Nothing 
Application.ScreenUpdating = True
End Sub

Last edited by macropod; 01-25-2017 at 02:20 PM. Reason: Added code tags & formatting
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Win10 Outlook keyboard error reduced all text all modules progdram wide markg2 Outlook 1 05-10-2016 08:17 AM
Combining 3 Modules into 1 Declaring a variable that is known across modules Officer_Bierschnitt Excel Programming 5 11-18-2015 12:28 PM
Combining 3 Modules into 1 Modelling training modules Vincent Project 3 09-03-2014 05:37 PM
Combining 3 Modules into 1 How do I stop making duplicates vba modules? chrisd2000 Excel Programming 1 06-28-2014 11:33 AM
Combining 3 Modules into 1 Empty Modules Greg S. Excel Programming 2 07-30-2013 01:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:57 PM.


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