PDA

View Full Version : Find Text and Copy into New Document



llyamah
03-10-2012, 05:02 AM
Hello All

I'm new to the world of VBA an keen to learn. I appreciate this is a really long post but I would be so grateful for any help. Even if you can't give me any code, if you could point me in the right direction where I can learn I would be so so grateful.

I have a report at work and would really like to do things to it that would impress my manager. I have attached a sample report that follows a similar structure to the report at work.

As you will see, it has headings (in red). The report at work also has sub-headings but I have not included them here. Underneath the headings, matters for certain countries are reported. Sometimes a country will only appear underneath one heading (depending on what that country needs to report) and so the countries can differ.

Here's what I want to be able to do:

If we call this sample report a 'world-wide report'. I want to be able to split this up to create 'country specific reports'.

In an ideal world, the user will be prompted for the country that they want a report for. It needs to be quite idiot proof - so a drop-down country choice might be good (e.g. if the user is prompted to type a country, they might type 'UK' whereas all of the information is reported under 'United Kingdom' headings).

If the user selects, for example, 'United Kingdom', the code should scan the document for anything for that country and copy and paste it into a new document. The new document should omit the country headings (since the 'country specific report' is for one country only, it will not be necessary to have these) but it should include any of the red headings. If there is a red heading where nothing has been reported from that country (e.g. in the sample report, France only appears under the first red heading) then the red headings should still appear, but the words "No information to report" should be displayed.

Thank you for reading.

fumei
03-10-2012, 04:44 PM
If the "chunks" - the contents by country - are bookmarked this is extremely easy to do. And, if they are bookmarked, additional content can be added to any chunk without messing up the extraction process. I am busy right now so I can not post back an extraction sample. Perhaps someone else can do it. I will not be able to do so until tomorrow.

But again, IF your starting file is bookmarked this is fairly easy to do. An example of bookmarks:

BrazilMeetings (holds all Brazil content re: meetings)
BrazilInspections (holds all content re: inspections)
BrazilEmployee (holds all content re: employee )

macropod
03-11-2012, 12:10 AM
Cross-posted (and solved by me) at: http://www.excelforum.com/word-programming/819038-word2007-please-help-a-newbie-get-started.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

fumei
03-11-2012, 07:43 AM
ah

llyamah
03-12-2012, 04:22 AM
Hello all

Thank you for the replies.

@macropod, you're right - I did cross post this but I didn't realise this was in breach of forum rules. Because it was on a different forum, I didn't realise this would be a problem, but now I know.

I also note that I have received answers in the other thread and have irritated people by not following other forum rules (re title and only making one post). Consequently I have been banned. I can assure you that I did not mean to do this. Since posting my question, I have only just had the opportunity to return to the thread. I really did not mean to cause anyone any offence, so I am sorry.

macropod
03-12-2012, 02:19 PM
Hi llyamah,

You have not been banned in the other forum. Rather, your rule breaches in that thread have resulted in it being closed.

llyamah
03-12-2012, 03:41 PM
@macropod, thanks for pointing this out. It had been showing as banned earlier, but I pm'd a mod to apologise. Thanks also for being a big help to me.