Counter for macro

Dear Experts:

below macro copies all parantheses at the end of the current document.
To spruce this very handy macro up, I would like a counter integrated,
that tells me via a MsgBox ...
.... how many parenthetical expressions have been copied or in the case
none were found
.... no parentheses found in current document

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub CopyParentheticalExpressions()

Dim str As String
str = ""
   ActiveWindow.View.ShowFieldCodes = True

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(findText:="\(*\)", MatchWildcards:=True,
Forward:=True, Wrap:=wdFindStop) = True

ActiveWindow.View.ShowFieldCodes = True
        str = str & Selection.range.Text & vbCr
        Selection.Collapse wdCollapseEnd
    Loop
End With
ActiveDocument.range.InsertAfter str

ActiveWindow.View.ShowFieldCodes = False

End Sub
0
andreas
4/15/2010 10:35:00 AM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
656 Views

Similar Articles

[PageSpeed] 32

Rather than continue to hand you finished code, may I suggest that you show 
what you have tried that doesn't work?

"andreas" <andreas.hermle@gmx.de> wrote in message 
news:a200891d-99ef-4e0b-821d-32f83e378197@z4g2000yqa.googlegroups.com...
> Dear Experts:
>
> below macro copies all parantheses at the end of the current document.
> To spruce this very handy macro up, I would like a counter integrated,
> that tells me via a MsgBox ...
> ... how many parenthetical expressions have been copied or in the case
> none were found
> ... no parentheses found in current document
>
> Help is much appreciated. Thank you very much in advance.
>
> Regards, Andreas
>
> Sub CopyParentheticalExpressions()
>
> Dim str As String
> str = ""
>   ActiveWindow.View.ShowFieldCodes = True
>
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
>   Do While .Execute(findText:="\(*\)", MatchWildcards:=True,
> Forward:=True, Wrap:=wdFindStop) = True
>
> ActiveWindow.View.ShowFieldCodes = True
>        str = str & Selection.range.Text & vbCr
>        Selection.Collapse wdCollapseEnd
>    Loop
> End With
> ActiveDocument.range.InsertAfter str
>
> ActiveWindow.View.ShowFieldCodes = False
>
> End Sub 


0
Greg
4/15/2010 11:09:37 AM
I agree.  If you need a counter for each iteration, then...add a counter.  if
you have problems with making it work, show us the code that is the problem.

Greg Maxey wrote:
>Rather than continue to hand you finished code, may I suggest that you show 
>what you have tried that doesn't work?
>
>> Dear Experts:
>>
>[quoted text clipped - 31 lines]
>>
>> End Sub

-- 
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201004/1

0
Fumei2
4/15/2010 6:27:55 PM
On Apr 15, 8:27=A0pm, "Fumei2 via OfficeKB.com" <u53619@uwe> wrote:
> I agree. =A0If you need a counter for each iteration, then...add a counte=
r. =A0if
> you have problems with making it work, show us the code that is the probl=
em.
>
> Greg Maxey wrote:
> >Rather than continue to hand you finished code, may I suggest that you s=
how
> >what you have tried that doesn't work?
>
> >> Dear Experts:
>
> >[quoted text clipped - 31 lines]
>
> >> End Sub
>
> --
> Gerry
>
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/wo=
rd-programming/201004/1

Hi Greg & Fumei,

thank you very much for your swift response.

I did some more trials and came up with my own solutions. It works.
Thank you for taking your time to look into my matter.

Regards, Andreas

Sub CopyParentheticalExpressions()

Dim str As String
Dim intCounter as integer
str =3D ""
   ActiveWindow.View.ShowFieldCodes =3D True
intCounter =3D 0
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(findText:=3D"\(*\)", MatchWildcards:=3DTrue,
Forward:=3DTrue, Wrap:=3DwdFindStop) =3D True

ActiveWindow.View.ShowFieldCodes =3D True
        str =3D str & Selection.range.Text & vbCr
        Selection.Collapse wdCollapseEnd
        intCounter =3D intCounter + 1
    Loop
End With
if intCounter =3D 0 then
   msgbox "None were found"
Else
   msgbox "Number found: " & intcounter
end if
ActiveDocument.range.InsertAfter str

ActiveWindow.View.ShowFieldCodes =3D False

End Sub
0
andreas
4/15/2010 7:31:52 PM
Reply:

Similar Artilces:

Text Only for Macros in Excel 2007?
Hello, I'm using the Office 2007 Beta and haven't been able to rename macros I've created and added to the ribbon. Even though I type the name I want, it only shows the symbol until you mouse over it, then it shows up with the correct name as a tool tip. I can't find the option to have it display "text only" instead of symbols. Does anyone know where this is? Thanks Jim ...

Macros don't work in shared workbook?
I could have sworn they did in others that I've used where the workbook is shared. Is there anything I should be looking at? I fully understand that we can't view or edit them when they're shared, but the macros should work, shouldn't they? It would defeat the purpose of having them, I would have thought. So obviously, I'm missing something. But what ... that's the question <g>. In general, macros should work in shared workbook--if the user allows macros to run(!). But maybe your macros are trying to do illegal stuff in that shared workbook and you'...

macro to Find Replace in Excel
Hi, I need to find double quotes in an excel file (could be a selectoin of rows) and replace them with nothing ( yeah just want to delete them) The built in Excel function to Find and Replace all gives me error "formula too long" Can someone please write me a small macro code thanks Hi I just tried with Find and Replace Replace All " with nothing entered removes all " from sheet/range Replace All "" with nothing entered removes all "" from sheet/range, but entries like " or " " remain unchanged. Arvi Laanemets "Nurddin&quo...

Help on a macro please
I have the code listed below that searches a folder and if it finds any PDF files its displays them with a hyperlink in the spreadsheet. My problem is that under the MAIN folder I have tons of files now and its very hard to find the PDF I am looking for. I redid my file structure under main and now I have folders for years 2010,2012,2013,2014,2015 and so on. Under each years directory are the directories for the 12 months of the year & under each of these months I have two folders A-cast & B-cast. What I would like is that the code could search the folders starting fo...

2 Macro Questions
If I assign a macro to a forms button on the sheet if I copy the book and load it on my friends computer do the macros go with them. Can a macro button be assign to a cell so when clicked it will print (72,8) from that cell, and what formula would I need? -- Thanks in advance for your help....Bob Vance .. .. .. .. Hi Bob 1. Yes, the macro code is copied as well 2. You can add some code to the Doubleclick event of your button. I'm not so sure what you mean with 'print'? Insert a value in a specific cell. If yes, try the following code: Private Sub CommandButton1_Click() Me...

Macro to select all and name range
I have a workbook with some macros that work on another workbook ("Data.xls"). One thing I want the macro to do, is to select everything in a worksheet named Survey and name the range "Database". This would be equivalent to go to the Data workbook and Survey worksheet, hitting Ctrl+Shift+End and enter Database in the name box. I can't record this action because the code specifies the cells included in the current version of Data.xls, and the number of rows will change. What code can I use to accomplish this? Richard Richard, Try this With Workbooks("D...

macro to all workbooks
is there possible to create a mocro for all excel work books. Two ways: 1. put the macro in your Personal.xls file. 2. put the macro in an add-in -- Gary''s Student - gsnu2007d "kaja48380@gmail.com" wrote: > is there possible to create a mocro for all excel work books. > ...

running a macro on a protected sheet
I've got a scenario where I've got several option buttons in groups to make choices. I've got the sheet protected so the buttons and/or groups can't be accidentally moved by the user. However, I've created a "clear all" button so the user can reset the form to redo their option button choices, if they need to. But, when protected, the macro attached to the "clear all" button won't work (due to the protection). How do I get around this? Thanks! Kriss, here is one way Sub test1() ActiveSheet.Unprotect password:="123" 'you cle...

Excel Macro's extended to a worksheet on ppt slide
Hello, I've written some VBA code and added it to my personal.xlsb file - which everything works great in excel. However, when I insert an Excel Macro-Enabled Worksheet into a PPT slide the macro's are not available to that embedded worksheet. This has worked in the past, but for some reason it stopped working. Any suggestions would be helpful. Thanks! In article <211446CC-D6C1-4053-9895-DD5D78E7A72E@microsoft.com>, VBA Newb wrote: > Hello, > > I've written some VBA code and added it to my personal.xlsb file - which > everything works great...

Macro code produces error
Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Hi everyone, <br><br>When I test the macro code below on Word 2004, I get the following error: <br><br>Compile error: user-defined type not defined <br><br>This only happens when I run the code on my mac. When I test it on a PC with Word 2007, it works fine. <br><br>I wondered if someone could run it for me and tell me if you get the same error? <br><br>Appreciate any assistance. <br><br>Sub GetImage() <br><br> Dim dlg As Office.Fi...

problem related macro
how we can execute macro tell me -- from sneha Hey guys!! Just wanted 2 tell you that...Jessie has already made pain's. talk 2 her. Bye! Gabri. "sneha karwal" <barbie_3883@yahoo.com> wrote in message news:eEXOS9TeKHA.5568@TK2MSFTNGP02.phx.gbl... > how we can execute macro tell me > > > > > -- > from sneha > > "sneha karwal" <barbie_3883@yahoo.com> wrote in message news:eEXOS9TeKHA.5568@TK2MSFTNGP02.phx.gbl... > how we can execute macro tell me > > > > > -- > f...

Macro for e-mailing cell range
I created a log in excel to manage our incoming documents and need to get a macro that will bring up a new outlook email with the subject as the name of the workbook and the body of the email as the text inputed with in a cell. I can get it to automatically email the entire sheet, but only need it to e-mail the information in the last updated cell of a particular column. This is the macro that I am currently using: Sub SendSheet() ActiveWorkbook.SendMail Recipients:="email address" Application.ScreenUpdating = True End Sub Thanks in advance for any help provided. Have a look at t...

Macro for Opening an Excel document
please does anyone know a macro or a way to open an excel document through MS access? I want to automatically open an excel doc at the end of running a macro. Thank you in advance. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1 Application.FollowHyperlink "C:\Folder\File.xls" -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele (no e-mails, please!) "axm0035 via AccessMonster.com" <u56602@uwe> wrote in message news:a88b896824356@uwe... > please does anyon...

Can one macro serve several check boxes?
I put several check boxes on a chart and assigned different macro to each of them. All each macro is doing is hide-unhide a specific column. Say I have ckeck boxes "Weight", "Length" and "Width". Assigned macro A, B and C accordingly. When I click "Weight" checkbox it calls macro "A" which toggles "hidden" status for column "J". So all macro have same functionality, only for different columns. I would like to build a _single_ macro, capable to know which control box was clicked. So, all check boxes will be assign...

Macro #37
I need to create a macro that will do the following: Sheet1 containg data (range A:J) In sheet2 I need macro to use ROW 1 Column A [ ="VICE" ] Column B [ ="I" ] Column C [ blank ] Column D [ =IF(Sheet1!I1="B","B1",IF(AND(Sheet1!I1="C",Sheet1!J2="C*"),"C1","NIL")) ] Column E [ a given date ] Column F [ =Sheet1!F1 ] Column G [ ="CONTROL " &Sheet1!E1 ] Column H [ =0 ] ROW 2 Column A [ ="ACTION" ] Column B [ ="#" ] Column C ["#" ] Column D [ =Sheet2!F1 ] Column E [ =She...

Macros and Great Plains
When I create a macro in Great Plains it seems to lose focus when I try to stop the recording. This happens even if I use shortcuts. It just does not stay in the field I finished in. In the past I have used Macros with Word mail merge in order to have a low tech update solution for my clients but in Version 10 the loss of focus is making it impossible. Any suggestions would be much appreciated. ...

Macro to Shade the selected cell
Hello, I am looking for a Excel 2007 macro that when run will shade the selected cell. Say I am in cell B9 and I run the macro, the cell will be shaded Yellow Thank you EggHeadCafe - Software Developer Portal of Choice XML Serializer Generator and Application Perfomance http://www.eggheadcafe.com/tutorials/aspnet/8eb0e68f-5496-4363-9cb9-dd68447ba187/xml-serializer-generator.aspx Turn on macro recorder and record the actions you do interactively. Press ALT+F11 and open the Module code to see what it has written. On Mon, 12 Oct 2009 16:25:42 -0700, Sukie Uppal wrote: >Hello, >I am lo...

Macro to Find, Cut, and Paste
I have 2 LONG columns that I need to make into MANY. I want to find a word in the active column, cut from that word down to the end and the adjacent cells; then paste them at the top of the next column. and do this for all occurences of that word. I'm confused about the two columns. I'm thinking that you want to break up your list of two columns based on the word in column A. But paste both columns to the adjacent columns. So this: $H$1 $B$1 $H$2 $B$2 $H$3 $B$3 $H$4 $B$4 $H$5 $B$5 $H$6 $B$6 $H$7 $B$7 aaaa $B$8 $H$9 $B$9 $H$10 $B$10 $H$11 $B$11 $H...

XLS To CSV Macro
Hello, What I am trying to accomplish is I have xls files that I need to keep updating, but also have to have the same xls file saved as a csv file for importing into a program. Is there away when I modify or add items to the xls the csv is automatically updated. I know I can link them and have tried that, but when I link the two files, I copy the complete xls and paste special to the csv, but I get all zeros on empty cells. Is there away around this? Thanks JR JR, A new CSV file must be written any time you want an updated csv copy. A csv file is a text file, and can contain no...

run macro based on Yes/No
I have some small macro buttons for printing. There are 12 of them and they are many pages so I wish to add into the macro (at the start) the oprion for the user to opt out of running the print macro using a Yes/No button. Can someone help as to how I can word the macro so that this will work? TIA sheila Is this what you want? '---- Sub test() Dim goOn As Integer goOn = MsgBox(prompt:="Do you want to continue?", _ Buttons:=vbOKCancel, Title:="Start printing?") If goOn = vbCancel Then Exit Sub MsgBox "Continue" End Sub '---- H...

Counter for macro
Dear Experts: below macro copies all parantheses at the end of the current document. To spruce this very handy macro up, I would like a counter integrated, that tells me via a MsgBox ... .... how many parenthetical expressions have been copied or in the case none were found .... no parentheses found in current document Help is much appreciated. Thank you very much in advance. Regards, Andreas Sub CopyParentheticalExpressions() Dim str As String str = "" ActiveWindow.View.ShowFieldCodes = True Selection.HomeKey wdStory Selection.Find.ClearFormatting With ...

Data Form, Countif and Macro
I have a spreadsheet where I've used a form to enter a customer's detail and the price of the ticket. I've got a macro that adds that information to a worksheet. I've then got a countif formula with absolute cell references to count the number of people wanting which starter, starter 1, starter 2 or starter 3. The problem I have is that the macros is adding the data to the top of the data in the worksheet by inserting a new row between the existing data and below the heading, which means the countif isn't seeing the newest data added to the sheet. Any help would be grea...

macro to search in a specific column
Hi, can anyone one modifie this macro to search only in a specifi column, in this case column B1.... Cells.Find(What:=Range("A2").Value, After:=ActiveCell LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByColumns SearchDirection:=xlNext, _ MatchCase:=True).Activate and would it be possible to change the font color to "red" to make i easier to see which cell is highlighted? Thanks Jean-Guy Collette Canad -- Message posted from http://www.ExcelForum.com One way: Dim found As Range Set found = Columns(2).Find( _ What:=Range("A2").Value, _...

Excel 2003 + macro
I want to place some code at the start of my macro. If D34 = no then a message box "Your printer code doesnt match" end macro else yes run the macro. Please help. Hi, Like this Set sht = Sheets("Sheet1") If UCase(sht.Range("D34")) = "NO" Then MsgBox ("Your printer code doesn't match") Exit Sub End If 'Yuor code -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Neil Holden&q...

Add a primary key via a macro
Hi - I am stuck. I have a macro that uploads text files via the "transfer text" action. I saved the import specification that I need and all works well EXCEPT for the primary key. I selected "Let Access add primary key", but it doesn't add it when I run the macro. When I upload the file by hand and select the import specification, the primary key is inserted. But when I run it via the macro, it isn't. What can I do to get primary keys added without having to upload each file by hand? On Tue, 12 Jun 2007 10:21:01 -0700, Diane, St. Louis <DianeStLouis@di...