Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to put dashes (-) after every third number?

Posted on 2012-08-23
8
Medium Priority
?
435 Views
Last Modified: 2012-08-25
I have documents that consists of a table on each page where I have to type in numbers in this format (###-###-###). I would like to just type in the numbers and then run a macro that would automatically enter the dashes.

I would like the macro to run from a command button on the right side of the first page but it can't print when the page is printed if that is possible!

I've attached a copy of the file I use to enter the numbers.

Thanks in advance for any help!
2011Box1-000-020-.doc
0
Comment
Question by:calbais
  • 4
  • 3
8 Comments
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 38327578
You could do a WildCard Find and Replace

Find: <([0-9]{3})([0-9]{3})([0-9]{3})>
Replace: \1-\2-\3

This is a good article on Word wildcards:
http://word.mvps.org/FAQs/General/UsingWildcards.htm
0
 
LVL 6

Expert Comment

by:Let's Go
ID: 38327764
Alternatively, you could embed an Excel spreadsheet in the Word document (or just use Excel) and set the number format in Excel.

To do this in Word 2010, click on the arrow next to Insert Table, then choose Excel Spreadsheet.
Inserting an Excel spreadsheet
Then select the relevant cells in the (Excel) table, right-click and choose Format, select Custom and type in the format as 000-000-000.
Setting the number format
The numbers will then automatically be displayed in your desired format.
0
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 38328448
If you require a macro, this will do it:
Sub FormatFileNumbers()
    With ActiveDocument.Range.Find
        .MatchWildcards = True
        .Text = "<([0-9]{3})([0-9]{3})([0-9]{3})>"
        .Replacement.Text = "\1-\2-\3"
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Open in new window

However, don't put a button on a document, especially one like yours. It is multi-page, so the button would not always be visible. You could create a QAT button or a command button. Or you could make a keystroke shortcut.
You need to report the Word version for further details.
0
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

Author Comment

by:calbais
ID: 38328658
Pfsnet... I would love to use Excel since I'm more familiar with it but I have no control over that at work. We have to use the Word document they provide. Thanks though!

GrahamSkan... I'm going to give your macro idea a try at work today. That looks like what I want. I'm using Word 2010. I'll put a button on the ribbon to activate the macro.
Thanks for your suggestion!
0
 

Author Comment

by:calbais
ID: 38331631
Thanks GrahamSkan. That macro works perfectly!!

I put a button on the ribbon so it would always be available to click but when I gave the document to a co-worker, the button was missing. Do you know if there is a way to make the button stay active when the document is distributed to someone else?

Regards

Cal
0
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 38331961
You would have to put the code and the keystroke in the document - or in its attached template which would also have to be distributed to your colleague.
0
 

Author Comment

by:calbais
ID: 38332319
Yeah, I did that but it didn't work!

Anyway, I'll figure it out. You answered my question here so here's your points.

Thanks for your help.

Regards

Cal
0
 

Author Closing Comment

by:calbais
ID: 38332323
GrahamSkan answered quickly  and accurately. His solution worked perfectly the first time!!

Thanks very much!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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 article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

578 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