Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,593 members, 7,809,147 topics. Date: Friday, 26 April 2024 at 01:21 AM

Help Needed From All Vba Programmers In The House! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Needed From All Vba Programmers In The House! (1429 Views)

10 Greatest Computer Programmers In History / No Programmers In Nairaland (2) (3) (4)

(1) (Reply) (Go Down)

Help Needed From All Vba Programmers In The House! by violent(m): 8:48pm On Jul 24, 2011
I was wondering if someone could help with a VBA macro in Microsoft Word that counts the number of Characters

I need a character count macro. Here's what I need it to do.

for example;

This line

This text field will change all the time. (X characters)

I need a character count of "This text field will change all the time." in the "X" position after it. So, I would want it to read,

This text field will change all the time. (41 characters)

I would think that this would be easy if you know what you are doing, but I don't. can someone Help?
Re: Help Needed From All Vba Programmers In The House! by Mobinga: 8:57pm On Jul 24, 2011
What have you done so far? Why don't you use an already made tool? Or Javascript on a webpage?
Re: Help Needed From All Vba Programmers In The House! by violent(m): 9:07pm On Jul 24, 2011
Mobinga:

What have you done so far? Why don't you use an already made tool? Or Javascript on a webpage?

I am actually very new to VBA programming and could ve done this easily on MS excel. but seeing as this is meant to be in MS word, it 's become a boil on my crotch.


here's wht ve done so far;


Option Explicit
Sub Word_counter()

Dim Wordlength As Integer
Dim WordNow As Integer
Dim x As Integer

ActiveDocument.Tables(1).Rows(1).Cells(1).Select
For x = 1 To ActiveDocument.Tables(1).Rows.Count
Selection.MoveRight Unit:=wdCell
WordNow = Len(Selection.Text)
Selection.TypeText Text:=WordNow
Next x

End Sub


rubbish, i know!
Re: Help Needed From All Vba Programmers In The House! by werepeLeri: 9:14pm On Jul 24, 2011
I thought there is a "len" function in VB

Search for Len in Google and see the use. Len(text) will give u the total characters in the variable "text"
Re: Help Needed From All Vba Programmers In The House! by violent(m): 10:05pm On Jul 24, 2011
werepeLeri:

I thought there is a "len" function in VB

Search for Len in Google and see the use. Len(text) will give u the total characters in the variable "text"



Yeah, i included the Len function in my VBA code--- see above.
Re: Help Needed From All Vba Programmers In The House! by violent(m): 10:06pm On Jul 24, 2011
So, i retweaked my code and this seems to return the number of characters quite well, but does anyone no of a way to do this automatically as i type?


Option Explicit
Sub Word_counter()

Dim Wordlength As Integer
Dim WordNow As Integer
Dim x As Integer
On Error Resume Next
ActiveDocument.Tables(1).Rows(1).Cells(1).Select
WordNow = Len(Selection.Text)
Selection.MoveRight Unit:=wdCell
If IsNumeric(WordNow) = True Then
Selection.TypeText Text:=WordNow - 2

End If

End Sub
Re: Help Needed From All Vba Programmers In The House! by Kobojunkie: 10:56pm On Jul 27, 2011
Re: Help Needed From All Vba Programmers In The House! by NET1(m): 6:02pm On Aug 01, 2011
why waste time writing the code?

Microsoft Word already has a tool for that. If you're using Word 2007, here's what to do:

Click on the Review tab
Click on Word count tab
Voila!

check the picture below:

(1) (Reply)

Gbenga Sesan To Interview Android Developer Challenge Winners / Building My First Game / ATM Card POS Devices (any Programmer)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.