Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Macro to insert selected paragraphs from webpage

Posted on 2010-11-10
4
Medium Priority
?
353 Views
Last Modified: 2012-05-10
Hi

This is to enhance the solution that was created here:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_25646695.html

I need to create a macro where a user will press a hotkey, then a prompt (form will look like "select-paragraph.jpg") will come up where they are to enter a number(s) to indicate which paragraphs they want inserted into their document.

The paragraphs will be coming from a word document (or local webpage) that resides on our server (paragraphs.doc).  As you can see in the paragraphs.doc file, there are numbers associated to the paragraphs.  So at the "Select Paragraph" prompt, they will enter "2,4,5", the macro will insert paragraphs 2,4 and 5.

 Paragraphs.doc
 Select Paragraph Form
0
Comment
Question by:SBFVAN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
lwebber earned 2000 total points
ID: 34111409
You don't need a macro for this. Open Paragraphs.doc and choose File, Save As. Save it as a template (.dot) file, and put it in a shared ntwork folder (let's call it F:\word\global. In Paragraphs.dot, for each paragraph:

1. Select the full paragraph.
2. Press Alt+F3 to create an AutoText entry. Name it p1 or p2 or p999.
3. Make sure the AutoText entry is saved in Paragraphs.dot (that should be the default).

While you're at it, you could precede each para with a separate one-line para showing its number. Makes it easier to keep track of which is which.

4. Save and close Paragraphs.dot

Now on any machine in the office, add Paragraphs.dot to the Global Templates and Add-ins list (Tools, Templates and Add-ins). You only have to add it once, but in future Word sessions you have to go in there and checkmark it to activate it. If that's too much work, then save Paragraphs.dot in the user's Startup folder -- it will appear on the Global Templates and Add-ins list with a checkmark every time you start Word.

Now for the UX. Enter p45 then F3. If you want to enter paras 1, 3, 6, 7, 10, and 15:

p1 F3 p3 F3 p6 F3 p7 F3 p10 F3 p15 F3

Yes -- this adds ONE keystroke to the total they would otherwise have to press (they have to type the "p" -- but they extra F3 is offset by no need for a comma).

If you need to change the source paras, just edit Paragraphs.dot. When you have modded a paragraph, re-create its AutoText entry, then save the document.
0
 

Author Comment

by:SBFVAN
ID: 34122734
Hi Iwebber

Thanks for the answer.

Just curious, would it be possible to grab the paragraphs from a website.  I'd prefer for it to grab the paragraphs from an official webpage to minimize the potential for error as well as being up to date.

Please advise

Thanks

SBFVAN
0
 
LVL 9

Expert Comment

by:lwebber
ID: 34122914
No. AutoText has to live inside a Word template. To use a web page as a source, you would need to write some VBA code. This will be unpleasant, because the custom code has to know the internal formatting of the web page so that it can pick off what to you seem like obvious paragraphs. You could make your life easier if you have control over the formatting of the web page, and use tags with ID attributes like Para1, Para2, etc. But still, the VBA code is highly non-trivial. Word has to instantiate its own web browser, navigate to the page, parse the contents, grab the paragraph, etc. And after all that, you're not going to get stable formatting (unlike the AutoText approach).

How often do the contents change? You could simply distribute updated copies of the template to your users in a self-unpacking Zip file that copies the template into the user's Startup folder.
0
 

Author Closing Comment

by:SBFVAN
ID: 34124145
Thanks
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question