NationStates Jolt Archive


Microsoft Word Macros

Zayun2
10-05-2008, 17:39
Hey, NSG!

I've been trying to make a somewhat complex macro for microsoft word, but I haven't done any coding in VB for about a year. Can anyone help me out with key words and such?

Basically I want to make a macro that puts the selected text into a string, and then goes through letter by letter, and anything that isn't a certain format is changed to a different format. Can anyone help me on this?

So far I know I have to declare a String and that I'm going to need a loop with nested if statements, but I don't remember how to do any of that in VB.
Galloism
10-05-2008, 17:40
Use switch statements instead of nested loops, but it's been a long time since I've done any of that either.
Zayun2
10-05-2008, 17:54
Use switch statements instead of nested loops, but it's been a long time since I've done any of that either.

Well, I've been using java and you can have and if statements, but I don't know if that's possible in VB and I certainly don't know how to do it. I also don't know how to get specific chars out of a String in VB, but I think if I could figure these things out and figure out how to do a loop, then I could code it.
Galloism
10-05-2008, 18:00
Well, I've been using java and you can have and if statements, but I don't know if that's possible in VB and I certainly don't know how to do it. I also don't know how to get specific chars out of a String in VB, but I think if I could figure these things out and figure out how to do a loop, then I could code it.

Well, as opposed to doing an If tempString == "Febuary" then tempString = "2" else If TempString == "March" then tempString = "3", else...

You could do a

Switch()

tempString == "January" then tempString = "1"
tempString == "February" then tempString = "2"

(that syntax is probably wrong, but you can google VB switch statements. using switches for long chains gives your code a little more structure and order, not to mention reduced processing time.)