Programmatically change paragraph placement in Word range - vba

I seem to be stuck with a rather simplistic problem when writing a macro for MS Word, I even feel quite embarassed for myself.
I have a range of paragraphs (content don't matter here) that need to be sorted by a given criteria (sorting is not the case here as well) - p1-p2-p3
After sorting let's say we'll have p2-p1-p3
I seem not to be able to code the very process of paragraphs exchanging places e.g.
The usual approach for variables does not really apply to Word's objects.
I'm not really looking for a code sample (but will look into ofc), but for a hint of what to approach to use. Thanks

Related

Extracting text from a pdf...selectively

Interesting challenge...I'm looking for ways to extract data from a pdf, selectively. These are a collection of research abstracts which consistently have pieces of text I don't want (e.g. author's names and email address, weblinks, location cities etc).
The body of the text is what I want, and I'd looked at using stopwords as a way to solve the problem, but it quickly becomes counterproductive (many of the stopwords are actually necessary words within the text body I need).
So, is there a way to almost do an opposite approach to using stopwords, based on large areas of text you want, only? For example, where there is a title and block of text (e.g. object, methods, results) could these sections of text be selectively extracted?
To add a bit of a challenge further, there isn't much consistency to the documents (so they don't all have the same headings or length).
If anyone has any experience or tips and recommendations it would be really helpful, as the alternative of manual copy and paste just isn't sustainable.
Many thanks,
Graham.

Change Info in Word from Excel VBA

I have a letter in Word that needs to be sent out to a number of contacts (example of letter). The only thing that needs to change in the letter is the recipients information
(example of how recipients info is stored), but I don't know what the best way to change this info is.
I did a little bit of research and what I've come across is that people either do a search and replace or use fields. I suspect that there is a better method than search and replace since I know exactly where the text needs to change. I'm thinking there might be something similar to named ranges like in excel?
Now this is where I came across fields, but to be honest I don't really understand them. I know they have a name but this whole equation thing throws me off. So my question is how do I change this information in the quickest/most efficient way?
I understand how to access and save word documents and am planning on using a loop to go through each row of contacts one by one, so if you have a solution you can leave that part out (unless you know of a better way!).

Count frequency of words in a list

I start by saying that I am not an expert user of VBA; I am just learning it.
I have a question regarding the possibility of counting text strings in Excel using a Macro. I cannot use the 'Countif' function, as there are more than 20,000 text strings in the Excel file, and it would be a lengthy procedure I guess.
I was therefore thinking about the possibility of using a VBA code to scan and organize text strings by their frequencies.
For instance, there are a set of words like this in my file (each in a different cell):
home,
balcony,
flat,
apartment,
home,
home,
garden,
thing,
revenue,
flat,
...
window
I would like to know if there's a way to make Excel scan all the different text strings and come back with the frequency for each of them.
I am aware that probably there are easier way to do it (e.g. Python or some add ins), but we have to do it at work, and I can't really ask my colleagues to learn Python or other programming languages, nor we have the capability to buy any software at the moment.
Thanks to those who can help!
Simple Pivot Table (without VBA - but could be code if needed)
See Debra's great website

how to insert a piece of text in all headers in a document with VBA

all the answers I can find (and all the examples elsewhere on the web) are about very complicated insert operations (only on 1 header, or only odd pages, or not using select, or some such).
How do you insert a simple piece of text into all headers in a word document using VBA?
There are a few solutions available to you - probably not what you want to hear, but when you use VBA you get more options as well as more things to think about!
I'd like to suggest two options that would work for most situations.
The first is to record a macro, then use the VBA code in the macro. This has the benefit of letting you see how the code reflects what is being done, and you can modify to suit your needs.
Another option would be to use the .Headers property, explained in detail here. This is a property of a section, and since each document contains an unknown number of sections you'll need to add a loop to apply this to each section.

Excel VBA - how to handle many cell references without creating a mess

Suppose you have an Excel workbook and you need to write a macro that takes inputs from many different cell references, and updates values at many different cell references, how do you keep the code neat and maintainable?
It would be helpful to know:
best practices
useful tricks
unavoidable difficulties
necessary trade offs
If there are links to existing guides or discussions that would be helpful too. I haven't been able to find any.
Edit: I found http://www.eusprig.org/best-practice.htm very useful - from the European Spreadsheet Risk Interest Group (EuSPRIG).
It slightly depends om what the macro is going to do, but I use 'calculation' sheets, where I gather together the data I need for the macro, and output the results there.
I tend to do this do in defined ranges.
The result data can then be referenced from elsewhere.
Tricks: One thing I do is to create a visual 'check off' for each piece of input data as it's used. This just enables me to make sure that all the data I thought I was going to use, I have used.
Following Naming criteria is better solution , irrespictve of language.
in_name_range, out_name_range
in_num_range, out_num_range
Check points and adding watch , would surely help.
If you are going for modularity, Take care about updated ranges
(As you can't return more than one value at a time better write ranges in some predefined order in some sheet. This works for me.)