Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-03-2023, 03:36 PM
VBAlearn VBAlearn is offline VBA macro issue Windows 10 VBA macro issue Office 2021
Novice
VBA macro issue
 
Join Date: Oct 2023
Posts: 7
VBAlearn is on a distinguished road
Exclamation VBA macro issue

I am having trouble, with vba macro that I got online to compare two word documents (RTF) files. However I am running an issue can you please help to correct the issue in the file?
Reference VBA MAcro 1: https://www.pharmasug.org/proceeding...020-AD-055.pdf

VBA macro Code

Sub Compare()
Dim wd As Word.Application
Dim odoc As Word.Document
Dim rdoc As Word.Document
Dim strOPath As String
Dim strRPath As String
Dim strCPath As String
Dim strORTFfile As String
Dim ofiles() As String
Dim i As Integer

strOPath = InputBox("Please enter the folder of original documents:")
strRPath = InputBox("Please enter the folder of revised documents:")
strCPath = InputBox("Please enter the folder to save the comparison: ")

Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
End If
ReDim Preserve ofiles(0)
strORTFfile = Dir(strOPath & "" & ("*.rtf"), vbNormal)

Do While strORTFfile <> Empty
ReDim Preserve ofiles(UBound(ofiles) + 1)
ofiles(UBound(ofiles)) = strORTFfile
strORTFfile = Dir
Loop
For i = 1 To UBound(ofiles)
If Dir(strRPath & "" & ofiles(i)) <> Empty Then
Set odoc = wd.Documents.Open(strOPath & "" & ofiles(i))
Set rdoc = wd.Documents.Open(strRPath & "" & ofiles(i))
Set ndoc = Application.CompareDocuments(OriginalDocument:=odo c, _
RevisedDocument:=rdoc, _
Destination:=wdCompareDestinationNew, _
Granularity:=wdGranularityWordLevel, _
CompareFormatting:=True, _
CompareCaseChanges:=True, _
CompareWhitespace:=True, _
CompareTables:=True, _
CompareHeaders:=True, _
CompareFootnotes:=True, _
CompareTextboxes:=True, _
CompareFields:=True, _
CompareComments:=True, _
CompareMoves:=True, _
RevisedAuthor:="Merck & Co., Inc.", _
IgnoreAllComparisonWarnings:=False)

ActiveWindow.ShowSourceDocuments = wdShowSourceDocumentsNone
ActiveWindow.Visible = False
ofiles(i) = Replace(ofiles(i), Chr(13), "")
ndoc.SaveAs2 FileName:=strCPath & "" & ofiles(i),_
FileFormat:=wdFormatRTF, LockComments:=False, _
Password:="", AddToRecentFiles:=True, WritePassword:="",_
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=0
odoc.Close SaveChanges = False
rdoc.Close SaveChanges = False
ndoc.Close SaveChanges = False
End If


Next
End Sub


End of VBA Macro Code

thanks
Reply With Quote
 

Tags
vba macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro security issue harry Outlook 1 01-19-2023 12:21 AM
VBA macro issue Path issue using a macro on the ribbon troels Excel Programming 1 05-26-2015 10:25 AM
issue in running macro in mac expert4knowledge Word VBA 5 08-13-2014 02:33 PM
MS Publisher Macro Issue Chayes Office 0 06-16-2013 11:36 AM
Macro Issue Basanth Excel 1 12-05-2008 08:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:16 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