PDA

View Full Version : Word Compare Side By Side



mosa182
03-14-2010, 03:44 AM
Hi There

This is the first time I have been on this forum, so please execuse me if this has already been done. I have some experience in programming, but I am finding VBA particularly frustrating.

I am wondiering if this is possible? What would the coding be?


I want to use a spin button and a label to switch between open word documents
the label will display that documents name
I presume I would need to save the open documents name into an array, setting the value using the application.countBut I don't know how to solve this. Any help would be appreciated :friends:

Cheers Joe

lucas
03-14-2010, 12:49 PM
Are you under the impression that a userform will remain visible when you switch to a different document?

It will not.

I didn't do the whole label and spin button thing but I did put together a listbox that you can click on to nav to any open document so you could begin to see the problem with your request:

see attached. Open several documents and run the userform in the attached doc. Click on one of them to activate that document.

A lot would depend on what you wanted to do with the documents you are navigating to. You don't have to make them visible to do most things.

mosa182
03-15-2010, 05:27 AM
I have noticed that if you change the Options : 'Show all windows on the desktop' so it is not true, the form will stay on top no matter how many documents you cycle through.

Cheers for your reply, I will look at the coding you used.

fumei
03-15-2010, 10:14 AM
You could make the userform non-modal. I have to ask what is the purpose of this. All open documents are accessible through the Window menu; or (depending) through the Taskbar. I am simply wondering what is being served by this.

lucas
03-15-2010, 10:35 AM
The userform in my example is non modal Gerry and it still goes behind any document you open using the userform.

I wonder about the need too.

fumei
03-15-2010, 11:00 AM
Sorry, I did not actually look at your example. Of course it goes behind any document you make Active (not open) from the userform. When you activate it, it gets the focus.

I still want to know what is the purpose of this. mosa182, as lucas mentions, if you are trying to perform action on the documents, 99.9% of the time you do not need to activate them. Word is very efficient at doing actions on document that are not active. Use document objects.

mosa182
03-15-2010, 12:51 PM
Hi guys

Yes I see I have been a little vague. lol

I am trying to design an effective training package to be used at my place of work. The package is designed to help learners use Word effectively.

On start up my code de-activates the 'show documents on taskbar' so that my training form is always visible regardless of the document. This however makes it difficult to see what documents are open, which is why I wanted to be able to show the users this.

I am now stuck on this code however:

ActiveDocument.Windows.CompareSideBySideWith Documents("UsingWord.docm")
Windows.ResetPositionsSideBySide

I want to comapre two documents side by side, the active one and one which is already loaded called UsingWOrd.

Sorry guys, I am pretty good at programming with other languages, but VBA I am finding confusing.

fumei
03-15-2010, 12:56 PM
Ummm, stuck how?

mosa182
03-16-2010, 02:09 AM
Hi , I keep getting runtime error and debug screen.

fumei
03-16-2010, 08:26 AM
When you mention errors please post WHAT the error is, and what line it is on.

mosa182
03-17-2010, 08:35 AM
run-time error 5941 -the requested member of the collection does not exist

Private Sub optAnswers_Change()
If optAnswers.Value = True Then
Dim objDoc1 As Word.Document
Dim objDoc2 As Word.Document
Dim appath As String
Set objDoc1 = ActiveDocument
appath = TotalAppath & "\activities\answers.doc"
Documents.Open appath
Set objDoc2 = Documents("Answers.doc")
objDoc2.Activate
objDoc2.Windows.CompareSideBySideWith objDoc1 <<< ERRROR LIne
Windows.ResetPositionsSideBySide

End If
End Sub
the answers doc loads up ok, but the error seems to be with the active document

PS totalappath = activedocument.path

mosa182
03-18-2010, 08:25 AM
Hi there

Having problems with this code. The code works with the intial active document. But when I load another document up (which should now be the active document) I get the following error:

run time error 5941: The requested member of the collection does not exist


If optAnswers.Value = True Then
Dim objDoc1 As Word.Document
Dim objDoc2 As Word.Document
Dim appath As String

Set objDoc1 = ActiveDocument
appath = TotalAppath & "\activities\answers.docx"
Documents.Open appath
Set objDoc2 = Documents("Answers.docx")
objDoc2.Activate
objDoc2.Windows.CompareSideBySideWith objDoc1 <<<ERROR ON THIS LINE
Windows.ResetPositionsSideBySide
End If


I have used the point-break tool and the values in the variables are fine. Like I said works fine with the intial activedocument, but does not work when I load another up.

fumei
03-18-2010, 08:39 AM
First of all, this
appath = TotalAppath & "\activities\answers.doc"
Documents.Open appath
Set objDoc2 = Documents("Answers.doc")
objDoc2.Activate
can be (and should be) coded as:
appath = TotalAppath & "\activities\answers.doc"
Set objDoc2 = Documents.Open appath
It makes the document object objDoc2 the given file.

However, regarding the error, 5941 means exactly what it says. Whatever the instruction is asking to do, the object does not exist. Although you do not say (and it is good idea if you do), I suspect you are using 2007. If so, I can not try to duplicate your issue, as I do not use 2007. And

Windows.CompareSideBySideWith

is not a valid instruction for me.

mosa182
03-19-2010, 03:53 AM
Hi I found the problem.

The file was read-only. I don't know why this stopped the code from running, but it did.

Cheers anyway, great help guys Joe

mosa182
03-23-2010, 05:03 AM
Hi does anyone know why the following wont work with files that are read-only or in 2010 compatibility mode? It works fine wiht normal documents.

If optAnswers.Value = True Then
On Error GoTo handler1
Dim objDoc1 As Word.Document
Dim objDoc2 As Word.Document
Dim appath As String
Set objDoc1 = ActiveDocument
appath = TotalAppath & "\activities\answers.docx"
Set objDoc2 = Documents.Open(appath)
objDoc2.Windows.CompareSideBySideWith objDoc1
Windows.ResetPositionsSideBySide
Exit Sub
handler1:
MsgBox ("Cannot compare: ensure documents are not read only")
End If