last day (14 days later) » 

1:04 PM
2
A: Open Word Document and Bring to Front

PaulFrancisHow about, docWord.Application.Activate

 
Leave that LOC. It is not really required, I was just playing with them both. (I will edit the reply). Feel free to mark this as answer, so other can benefit from this.
 
+ 1 :) Simplest would have been objWord.Activate ?
 
@SiddharthRout, It would have indeed been more simple ;)
 
True. However a word of caution. .Activate is not a reliable approach as objWord.Activate will not work as expected if multiple files are opened in the same instance objWord but in different windows. ;)
 
Even if the Object has been declare/set to a particular file? If Word.Application.Activate is used, then there is a possibility for the Activate method to not trigger the right file. If an instance of the file has been set to the docWord Object, then Object.Activate should only activate the instance of the Object, right? Maybe I could be wrong. I will do a simple test and find out ;)
@SiddharthRout, had a quick play around. Maybe I am doing it wrong, but I can get the right file brought in fore ground if I use docWord.Activate, but if I used Word.Application.Activate then I get the per-opened file popping up instead. Which is what I based my theory for an answer. Please feel free to correct me if I am wrong.
 
1:04 PM
Strange. because I can't get that to happen :) The code that i am using is shown below
objWord is nothing but docword1.application or docword2.application. And in your case the code will always take the last document
I have this window open in one of the firefox tabs if you would like to discuss
 
Well, I should have mentioned that I did use the code docWord.Activate and not docWord.Application.Activate
My bad, sorry if you remove the application word it would bring the right file to the foreground.
:(
 
docWord1.Activate will also not bring it to the front :)
The best and reliable way is to use the API FIndwindow and then use Setforeground window. You can never go wrong there :)
 
Absolutely no doubt in using an API
Just not sure why it is working for me and not for you.
 
I used this
Sub Sample()
    Dim objWord As Object, docWord1 As Object, docWord2 As Object
    Dim strPath As String
    Dim hwnd As Long

    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True

    '~~> Change this to the relevant Filename and path
    strPath1 = "C:\Users\Siddharth Rout\Desktop\1.docx"
    strPath2 = "C:\Users\Siddharth Rout\Desktop\2.docx"

    Set docWord1 = objWord.Documents.Open(FileName:=strPath1, ReadOnly:=True)
    Set docWord2 = objWord.Documents.Open(FileName:=strPath2, ReadOnly:=True)
nothing comes to the front :)
 
I am using this.

    Public Sub defendMyHonor(strPath As String, strPath2 As String)
        Dim objWord As Object
        Dim docWord As Object, docWord2 As Object

        Set objWord = CreateObject("Word.Application")
        objWord.Visible = True

        Set docWord = objWord.Documents.Open(Filename:=strPath, ReadOnly:=True)
        Set docWord2 = objWord.Documents.Open(Filename:=strPath2, ReadOnly:=True)

        docWord.activate

        Set docWord = Nothing
        Set objWord = Nothing
 
1:13 PM
But does that bring the docword in front of Excel? Because your code also doesn't bring it in front :)
 
Hmmm is there a difference because I am using Access instead of Excel. Will give it a try in Excel.
Ek second.
 
did you say "Ek" :D
 
Ha Ha ! huh
 
since the question is from excel-word. i didn't try it from access. btw "Ek nahi thees second le lo :P"
 
Well this is very embarrassing. It is not working as I hoped to. Unsure why it works on Access though.
 
1:18 PM
and hence .Activate is unreliable like I mentioned :)
 
thees sec neih bhai. lol. Testing hey na. ;)
 
hope that clears the confusion? cya
 
Yes. You are the MAN !
 
you might want to edit your post ;)
bye
 
bye
All done sir ji ! Dhanyavad.
 

last day (14 days later) »