Consulting

Results 1 to 3 of 3

Thread: Loop to open Word Docs - Avoid Maximizing Already Open Doc

  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    66
    Location

    Loop to open Word Docs - Avoid Maximizing Already Open Doc

    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

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    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

  3. #3
    VBAX Regular
    Joined
    Apr 2017
    Posts
    66
    Location
    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
    Last edited by macropod; 06-27-2018 at 09:44 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •