TRENDING NEWS

POPULAR NEWS

In Vba Word How Would You Loop Through Each Section And Message Box Out The First Sentence Of Each

How do I write LOOP for "DOUBLE YOUR PAY" application (VB)?

Ok so let me break down your question. Basically you want to know how to use loops i'm thinking. Well considering you seem to be trying the pay for a month if it were doubled each day, lets look at how we could use a For loop to achieve this.

A For loop is really useful as it can progress through a series of data and execute a chunk of code each time it steps through the series of data, most commonly we would use a range of numbers. heres a little example:

For i as integer = 1 to 30
'Your code for doubling the money in here
Next

So this is one solution, however we could use a Do Loop Until, loop instead as a for loop is more useful if we actually want to use the series as we progress through it. The key part of a do loop until is how we get out of the loop, if we don't we will be stuck in it forever. Let's have a look at a do loop until:

Do
'your code for doubling pay here
Loop Until 'some condition.

We need a condition to exit this loop, and in your case this should be the day number, which implies we need a variable to act as a counter. So the code becomes this:

dim daycounter as integer = 0
Do
'Your code for doubling pay
daycounter += 1
Loop Until daycounter = 30

2 things to notice here, firstly i make sure to increment the counter in the loop so that we don't get stuck in the loop, and also notice how i have put the value equal to 0 to start with and the incrementation of the daycounter at the end of the loop, this means that once we have done the doubling the daycounter variable increases by one, and is equal to the amount of doubles we have performed.

These are just 2 loops you could use, you can also use things like Do while, do until, loop while, which are all fairly similar, and notice how do until is very similar to loop until, the difference is that the do until, will check the condition before executing the block of code, whereas we have to do the block of code before checking a condition in the loop until, loop.

One more thing that i think would be useful to you. You might want to use the days in the month as a counter, but obviously these change each month, so here's a little line of code to assign the current number of days in the month to a variable that you might use latter:

Dim daysinmonth as integer = Date.DaysInMonth( Date.Now.Year, Date.Now.Month)

Hope your coding goes well :)

How do i make a table contents on word?

Here's how to get Word to make a Table of Contents for you.

In versions of Word prior to Word 2007:

1. Go to the point where you want the TOC to go.
2. Click on the Insert->Reference->Index and Tables menu item.
3. Select the Table of Contents tab.
4. Under Print Preview there are a few options you may wish to select or deselect, including one for tab leaders.
5. Click OK.
6. This will insert a table of contents field in your document, but since you don't have any entries, you'll see this message:

Error! No table of contents entries found.

Not to worry. To make entries, you'll have to use Heading styles. Heading 1, Heading 2, Heading 3 are by default collected for the Table of contents, but you can play around and get others also. There's even a way of putting in entries that aren't flagged by style.

The Table of Contents also doesn't continually update itself. You have to tell it to whenever you want it to:

1. Right click in the table and select Update Field.
2. An Update Table of Contents dialog box will appear.
3. Click the Update Entire Field button.
4. Click OK.

You'll also probably want to put the Table in a separate section (use the Insert->Break menu item and select Section/Next page from the list).

And you may want to number the pages following the TOC starting at 1.

1. Click anywhere In the first section after the TOC.
2. Click the Insert->Page Numbers menu item.
3. In the Page Numbers dialog box, click the Format button.
4. Click Start At.
5. Click OK.
6. DO NOT CLICK OK ON THE PAGE NUMBERS DIALOG BOX OR YOU'LL INSERT A DEFAULT PAGE NUMBER FIELD. Click CANCEL instead.

In Word 2007:

1. Click where you want the Table of Contents to go.
2. Click on the References tab on the Ribbon.
3. Click the Table of Contents Icon.
4. Select Insert Table of Contents near the bottom of the list.
5. Continue as in Step 4, way above.

There is also a way to get non-heading entries into the TOC. Investigate the Options button/Table Entry fields on the TOC dialog box and the Table Entry Field in the Help system.

Hope that helps.

How do I stop an excel macro stuck in an endless loop?

Twenty years ago, CTRL + Break was very effective at stopping runaway Excel code. I find that trick seldom works these days, however.When I test VBA code, I make sure to save the file first and always have the Task Manager running. If an infinite loop arises, I use the Task Manager to kill Excel. And if that doesn’t do it, I force the computer to reboot.If I suspect a chance the code may take a long time to run, I will limit the number of loops that it goes through for testing. This allows me to debug the code and then optimize it for running quickly.The Timer function in VBA returns the number of seconds (and milliseconds) since midnight. I use Timer to keep track of execution time by storing the value of Timer at the top of the code, then using the following statement:Debug.Print Timer() - StartTimeto display (in the Immediate pane) the number of seconds that it took to run the code. This lets me know whether I am improving execution speed. On long-running code, I can usually find ways to increase the speed by a factor of 10 to 100.

How would you write a program to count the vowels in a sentence?

Oddly, everyone so far have given wildly erroneous solutions. Even in normal English text you will encounter words and names with letters such as é and more exotic ones like ï (in Caïssa, the goddess of chess, for example). Other Latin languages have vowels such as å, ä, ö, ü, æ and ø. Remember that "English text" also means parsing the entire English Wikipedia, which contains some pretty funky characters.The standard way of solving these types of problems is to use Unicode Character Categories. Unfortunately there is no category for vowels in all scripts. Some quick Googling makes it clear that lists of all vowels are hard to come by.This is a very hard problem.Then comes the problem of parsing text into sentences. Not at all easy. The naive solution would be to split at ".", "?" or "!", but then you would for example split initials in names (J.R.R Tolkien). Splitting on one of those characters followed by white space would get it mostly right, but it would miss sentences at the end of a string, so you need to allow those marks followed by end-of-string as well. Also, remember that ".?!" are not the only symbols that can end a sentence. I don't know which symbols do in all languages, but for example the single character "‼" would probably serve well at the end of a sentence.Unfortunately this is not good either, since some people, like George W. Bush use period followed by space. How would you know that "George W" is not a sentence? If you know that the text is correctly formatted English, you can try to use a Natural Language Parser (see: The Stanford Natural Language Processing Group)  to split the text into sentences. This is of course just an approximate solution.Summary: If you know the text is in English, a half-assed solution would be to  compile a list of all vowels in Latin script (remember both lower and upper case) and use a statistical NLP parser to parse the text into sentences. And then count.Text is hard.

How do I loop through all the folder or files starting with the same phrase only in Microsoft excel vba?

I’m assuming that you want to do something with the files you match.(If not, there are already a squillion tools out there that will find and report all files that match your ‘phrase’.)You can use VBA’s DIR function to report all files in a folder, one at a time. It’s up to you how you handle each one.But, at the folder level there’s a gotcha … should you do anything to any of the files in the folder, then DIR will ‘break’.[ myFileName = dir(“*myPhrase*.*”) will find you the first match.From then on, you just use myFileName = dir() to get subsequent matches, until myFileName =”” .But, if you do anything to any of those files, dir() will lose its place and no longer know what you’re talking about.]So,Cycle thru all the file names in the current folder, adding each to a Collection. Then, once you know them all, go back thru the Collection one filename at a time and do whatever it is you need to do.To span directory trees, you need to distinguish between files and folders; DIR can do that for you too. (You will also need to learn how to distinguish between System files, hidden, “.” & “..” equivalents etc. But that’s not so hard.)Push each folder you encounter onto a stack. Once you’ve finished with a folder, Pop a previously encountered folder off the stack and process that one (use chDir), just like the last one.When your stack is empty, you’re done.I’m not giving you this code. Sorry. It’s not very hard to do yourself, it’s great practice, and you’ll find a million uses for your tool once you’ve built it.(For example, I regularly use StueysShitSaver to do (moderately) fast backups that function and report in Excel.)

Help with Visual Basic Looping structures?

1) you need to loop through the string and see what characters match your character - i won't write the whole program, just the snippets you need (because i'm not a VB coder... :-) )

Dim p as Integer
Dim counter as Integer
For p = 0 to theString.length-1
If theString.Chars(p) == searchingChar
counter = counter + 1
End If
Next p
Return counter

2) just access the first, middle, and last and concat them together
Dim first as Char
Dim mid as Char
Dim last as Char
first = theString.chars(0)
mid = theString.chars((theString.length - 1) / 2)
last = theString.chars(theString.length - 1)
Dim total as String
total = first & mid & last
Return total

3) go through theString to see if searchString starts there... if you get to the end of searchString and you found a match the whole way, return the start position - otherwise go through the rest of the string, keeping searching ... return -1 if you don't find anything valid
Dim p as Integer
Dim c as Integer
For p = 0 to theString.length - searchString.length
Dim good as Boolean
good = true
For c = 0 to searchString.length
If theString.chars(p+c) != textString.chars(c)
good = false
End If
Next c
If good == true
Return p
End If
Next p
Return -1

good luck!

Word Macro or VBA code for automating find - replace using a data file?

I have a file thant contains abbreviations I want to use in certain documents. These are in a word file in a table (two columns, word and abbreviation). I want to write a macro which, when run, will replace all words appearing in another document with the abbreviations.
What I think needs to be done is make some kind of a loop with the following steps:-
Open replace dialog box - open abbreviation data file - do till not end of file - select first word place in find box, select corresponding abbreviation place in replace with box - select original document - replace all - next word from the data file.

Can someone help me write this code please?

TRENDING NEWS