Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2017, 08:04 AM
elbartje elbartje is offline Loop true all opned word document Windows 10 Loop true all opned word document Office 2016
Novice
Loop true all opned word document
 
Join Date: Jun 2017
Posts: 4
elbartje is on a distinguished road
Default Loop true all opned word document


Hi all

I want to loop true all opened word documents but my code stays on the first selected file. It also only just loops 2 times even if I have more files opened.

Dim wd As Range

For Each wd In ActiveDocument.Words

wd.Select
MsgBox (wd.Document.Name)
'Do stuff

next wd
Reply With Quote
  #2  
Old 06-12-2017, 05:27 PM
Guessed's Avatar
Guessed Guessed is offline Loop true all opned word document Windows 10 Loop true all opned word document Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That code is only looping Words, not documents. Try nesting your loops like the following aircode
Code:
Dim aDoc as Document, wd as Range
For each aDoc in Application.Documents
  For each wd in aDoc.Words
    'do stuff
  Next wd
Next aDoc
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VB for Word - Need macro to loop each line in a document NDeane Word VBA 5 12-22-2015 08:12 PM
Loop true all opned word document Loop through files and Copy Table Row and Paste into Different Document spiderman1369 Word VBA 2 10-15-2014 08:30 AM
Loop true all opned word document Loop through each Line in Word ilcaa72 Word VBA 4 02-13-2014 11:48 AM
Loop true all opned word document Loop action in Word until not found kilburfi Word VBA 2 07-12-2013 01:26 AM
Loop true all opned word document Macro to loop in Word Yamaha Rider Word VBA 2 02-07-2012 05:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft