View Single Post
 
Old 12-20-2012, 11:48 AM
marceepoo marceepoo is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Sep 2012
Posts: 22
marceepoo is on a distinguished road
Default Macro operates on wrong document window

If I have two or more word files open when I run this macro, sometimes the macro will operate on a file other than the one that was topmost on my screen when I hit the button that triggered the macro.

Does anyone know how I can tell vba to run the macro on the document window that was topmost on my screen when I hit the button that triggered the macro?

Thanks for any tips.

Marc


Code:
Sub subRarBakupDoc() 'Source = NMa
'
'
    Dim dtmStart As Date
    Dim dtmEnd As Date
    Dim intTotalTime As Integer
    
    dtmStart = Now()
    
    With ActiveDocument
    End With
    
    With ActiveDocument
        ActiveDocument.ActiveWindow.SetFocus
        Dim strActiveDocFullName As String
        Dim strActiveDocDir As String
        Dim strVbScriptFullName As String
        Dim strPythonScriptFullName As String
        Dim strCmdLin01 As String
        Dim strRetVal As String
        Dim objWshShell As Object
        Dim strMsgBoxMsg As String
        
        strActiveDocFullName = Chr(34) & ActiveDocument.FullName & Chr(34)
        strActiveDocDir = Chr(34) & ActiveDocument.Path & Chr(34)
        
        strPythonScriptFullName = Chr(34) & "C:\Apps\UtilitiesByMarc\RarCpyBakupSelected_file_nu_.py" & Chr(34)
    
        strCmdLin01 = Mac02.fnPythonFullName & " " & strPythonScriptFullName & " " & strActiveDocFullName
        'strCmdLin01 = "C:\Apps\ UtilitiesByMarc\MessageBoxe_SAVE_.vbs" & " " & strActiveDocFullName
        
        'MsgBox strCmdLin01
        
        Set objWshShell = CreateObject("WScript.Shell")
        objWshShell.Run strCmdLin01, 1, True 'http://ss64.com/vb/run.html  objShell.Run (strCommand, [intWindowStyle], [bWaitOnReturn])
                                            'intWindowStyle = 1 = Activate and display the window.   bWaitOnReturn = True / False
        
        'strRetVal = Shell(strCmdLin01, vbNormalFocus)
    End With
    
    dtmEnd = Now()
    
    intTotalTime = CInt(dtmEnd - dtmStart)
    
    'MsgBox "intTotalTime = " & intTotalTime
    
End Sub 'subRarBakupDoc()
Reply With Quote