PDA

View Full Version : [SLEEPER:] Loop to open Word Docs - Avoid Maximizing Already Open Doc



BrI
06-15-2018, 08:42 AM
The code below opens Word docs using file paths in each cell in Excel range.

Code works to open the docs OK, but the issue is that it will also maximize one unrelated, already open Word doc (if it exists) that is minimized to the tool bar.

Is there a way to avoid this?


Dim Shex As Object
Set Shex = CreateObject("Shell.Application")
Dim rng As Range
Dim ws As Worksheet
Set ws = Worksheets("FilePaths")
NumRows = Range("B2", Range("B1").End(xlDown)).Rows.Count
Set rng = ws.Range("B2:B" & NumRows + 1)
For Each cell In rng
Shex.Open cell.Value
Next cell
End Sub

offthelip
06-17-2018, 03:24 PM
I would try forcing EXCEL to start a new version of Word, with code like:


Dim wordApp As Word.Application

Set wordApp = CreateObject("word.Application")
wordApp.Visible = True




Note: totally untested just a guess

BrI
06-27-2018, 08:58 AM
Thanks, but this (omitting the Dim statement as throws an error) opens a new blank Word window and maximizes that as well as an existing minimized document.

Also, Setting
wordApp.Visible = False will not show a new blank Word window, but an existing minimized Word document is still maximized - the original problem.

Resolved using the
Documents.Open method for word docs