Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-07-2016, 06:29 PM
Irene H Irene H is offline Looping through word and writing to excel when certain conditions are met Windows 10 Looping through word and writing to excel when certain conditions are met Office 2016
Novice
Looping through word and writing to excel when certain conditions are met
 
Join Date: Jul 2016
Posts: 3
Irene H is on a distinguished road
Default Looping through word and writing to excel when certain conditions are met

Apologies up front if this has been answered in a previous post, however I've been looking for a number of days now and haven't been able to solve my problem.



I have a macro which loops through all paragraphs in a word document.

While it loops through, it evaluates the font style, and updates a number of variables which will be passed to excel when a condition is met (para.style = normal). I then want to take the variables and write them to a new row in excel. It then goes back to the word document and resumes looping through the paragraphs until the condition is next met.

When I was first writing the code, I was using an earlier OS and version of office, and the existing code worked to completion and the excel worksheet was fully populated with the full content of the word Document.

When I tried to run the code on my machine (which I use more often than not) and start handling other issues (tables), the macro worked to the point of creating the first row in excel, but when it came to writing the next (and subsequent rows), it doesn't appear to activate the worksheet.

I have attached the code and the target xls sheet. I'd be appreciative if anyone can steer me in the right direction.
Attached Files
File Type: xlsx Derived Requirement and Test Spec Template.xlsx (11.4 KB, 9 views)
File Type: txt word vba horvat thread 1.txt (6.3 KB, 10 views)
Reply With Quote
  #2  
Old 07-08-2016, 05:37 AM
DougMVP DougMVP is offline Looping through word and writing to excel when certain conditions are met Windows 7 32bit Looping through word and writing to excel when certain conditions are met Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 50
DougMVP will become famous soon enough
Default

I would suggest that in your code, you start Excel and open the workbook right at the start, rather than doing that each time a Normal style paragraph is encountered.
Reply With Quote
  #3  
Old 07-10-2016, 05:59 PM
Irene H Irene H is offline Looping through word and writing to excel when certain conditions are met Windows 10 Looping through word and writing to excel when certain conditions are met Office 2016
Novice
Looping through word and writing to excel when certain conditions are met
 
Join Date: Jul 2016
Posts: 3
Irene H is on a distinguished road
Default

Doug,

Thank you for that suggestion.

The problem with having it where it was (other than being untidy and redundant) was that I re-initialised the xlRow variable to 2 every time, so in fact I was simply rewriting everything to the same row, instead of incrementing the counter and writing to the next row.

One of those mistakes when you're overtired and been looking at something too long!


Cheers,
Irene
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Formula for Multiple Conditions & Results nowco Excel 4 03-16-2016 11:24 AM
Writing PDF from Mac Word dickmill Word 0 01-13-2016 08:17 AM
Looping through word and writing to excel when certain conditions are met Generating Multiple Word Docs from Master Depending on Conditions ljg713 Word VBA 6 12-09-2015 03:23 PM
Looping through word and writing to excel when certain conditions are met How to stop MS word writing in margin gerretw Word 2 02-05-2013 07:01 AM
Looping through word and writing to excel when certain conditions are met Replacing cells in Excel-Very basic with minor conditions mag Excel 1 10-26-2012 10:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:48 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