Go Back   Tech Support Forum > Microsoft Support > Microsoft Office support

w3k word macro ....(addition)

This is a discussion on w3k word macro ....(addition) within the Microsoft Office support forums, part of the Tech Support Forum category. hi there , (after a long time busy with some writing) I have got this code from macropod (thanks!) Code:


Closed Thread
 
Thread Tools Search this Thread
Old 03-20-2012, 10:34 AM   #1
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



hi there , (after a long time busy with some writing)

I have got this code from macropod (thanks!)

Code:
Global chain As String
Sub ParseREVERSE()

Dim i As Long, StrNew As String, StrTmpA As String, StrTmpB As String, StrEnd As String
With ActiveDocument.Range
'select whole document
.Start = ActiveDocument.Range.Start
.End = ActiveDocument.Range.End
'setup the find parameters
  With .Find
    .ClearFormatting
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Replacement.Text = ""
    .Text = "\[[0-9]{1,}\]"
  End With

'each of these will cause a find for [numbers]
.Find.Execute

  Do While .Find.Found
    .Duplicate.Select
    Answr = MsgBox("Replace this tag?", vbYesNoCancel)
    If Answr = vbYes Then
       .Text = place(.Text)   ' we will make the function shortly
    ElseIf Answr = vbCancel Then
       Exit Do
    End If

    .Collapse wdCollapseEnd
    .Find.Execute
   Loop
   
End With

End Sub

Function place(num)

quote = Chr(34) ' constant for "

x = Val(Mid$(num, 2)) 'the numberpart in number] note the opening [ is gone

ID = Right$("0000" & (2 * x) - 1, 4) 'front loaded string to give leading 0s for 4 characters

href = Right$("0000" & (2 * x), 4) 'as above

If InStr(chain, "[" & num & "]    ") = 0 Then
    'capture the first use of [num]
    chain = chain & "[" & num & "]    "
    'the whole replacement string
    place = "<a id=" & quote & "C0RE" & ID & quote & " href=" & quote & "#C0RE" & href & quote & ">[" & x & "]    </a>"
Else
    'short form
    place = "<a href=" & quote & "#C0RE" & href & quote & ">[" & x & "]    </a>"

End If
End Function
it works well for single numbers inside [] that for like [12] or [455] etc,

I need some changes here for the numbers inside the [] with same rules
i.e for
[12, 34, 56]
or
[6, 34, 56, 78]

kindly suggest ,

thanks,

__________________
newbeeee is offline  
Old 03-20-2012, 01:29 PM   #2
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



using this \[[0-9]{1,}, [0-9]{1,}, [0-9]{1,}\]
the numbers could be found like
[12, 23, 34]

but finding any numbers between [] is unknown and then applying rule to each and every in between [].....

need help here

__________________
newbeeee is offline  
Old 03-20-2012, 03:57 PM   #3
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



Hi Newbee,

You could change:
.Text = "\[[0-9]{1,}\]"
to:
.Text = "\[[0-9, ]{1,}\]"

This will find all square brackets with any mix of numbers, commas and spaces between them.
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-20-2012, 04:11 PM   #4
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



yes it finds that in this way, but as i took example as

[12] [1, 22, 12] [1]

it gives

output as

<a id="C0RE0024" href="#C0RE0023">[12]</a> <a id="C0RE0002" href="#C0RE0001">[1]</a> <a id="C0RE0002" href="#C0RE0001">[1]</a>

required here is

<a href="#C0RE0023">[12]</a> [<a href="#C0RE0001">1</a> <a id="C0RE0044" href="#C0RE0043">22</a> <a href="#C0RE0023">12</a>] [<a href="#C0RE0001">[1]</a>]
__________________
newbeeee is offline  
Old 03-20-2012, 04:18 PM   #5
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



kindly refer my previous post which will be of much use for you in suggestion, thanks
__________________
newbeeee is offline  
Old 03-20-2012, 04:38 PM   #6
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



If you wanted to do something more sophisticated than just finding brackets with the extra content, you should have said so. In any event, the code you posted is not code that I have provided. It looks like you took something that I provided and changed it, by adding a function of your own. As far as I am concerned, you're on your own with that.

As for
Quote:
kindly refer my previous post which will be of much use for you in suggestion
If you can't be bothered posting a link, No one will be bothered looking for whatever post you're referring to. You have made many posts and I have no idea which one(s) you are referring to.
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-20-2012, 05:10 PM   #7
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



sorry for that, its all my bad,
---------------
I will try to explain here what I have done, is in the code as provided,
it search a number with in [] and replace with a code
say

[12]

now the formula here is

Code:
x = Val(Mid$(num, 2)) 'the numberpart in number] note the opening [ is gone

ID = Right$("0000" & (2 * x) - 1, 4) 'front loaded string to give leading 0s for 4 characters

href = Right$("0000" & (2 * x), 4) 'as above

If InStr(chain, "[" & num & "]        ") = 0 Then
    'capture the first use of [num]
    chain = chain & "[" & num & "]        "
    'the whole replacement string
    place = "<a id=" & quote & "C0RE" & ID & quote & " href=" & quote & "#C0RE" & href & quote & ">[" & x & "]        </a>"
which gives output as

<a id="C0RE0024" href="#C0RE0023">[12]</a>

but if this [12] gets repeated very next time
we use formula(code)
Code:
Else
    'short form
    place = "<a href=" & quote & "#C0RE" & href & quote & ">[" & x & "]        </a>"
which give a output as

<a href="#C0RE0023">[12]</a> only

----------
now the problem here is that it looks for only one digits inside [] say [23] or [45] only

I am looking for a solution wherein we can serach any number of digits inside []
say [12, 34, 4, 56]

and then apply the said formula(code) to them also

this is all required.
-----------
__________________
newbeeee is offline  
Old 03-22-2012, 04:13 PM   #8
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



I think I need to wait ....
__________________
newbeeee is offline  
Old 03-22-2012, 07:54 PM   #9
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



Try:
Code:
Sub ParseEquationRefs()
Dim StrNew As String, StrTmp As String, StrLo As String, StrHi As String
Dim Answr, ValA As String, ValB As String, StrID As String
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Text = "[\[0-9, \]]{3,}"
    .Replacement.Text = ""
    .Execute
  End With
  If .Find.Found = False Then MsgBox "No Equation References to parse", vbInformation
  Do While .Find.Found
    .Duplicate.Select
    Answr = MsgBox("Replace this tag?", vbYesNoCancel)
    If Answr = vbCancel Then
      Exit Do
    ElseIf Answr = vbNo Then
      GoTo NextItem
    End If
    StrTmp = Replace(.Text, " ", "")
    If UBound(Split(StrTmp, ",")) = 0 Then
      StrTmp = Replace(Replace(StrTmp, "[", ""), "]        ", "")
      ValA = Format((2 * StrTmp), "0000")
      ValB = Format((2 * StrTmp) - 1, "0000")
      StrNew = "<a =""C0RE" & ValA & """ href=""#C0RE" & ValB & """>[" & StrTmp & "]        </a>"
    ElseIf UBound(Split(StrTmp, ",")) = 2 Then
      StrTmp = Replace(.Text, " ", "")
      StrLo = Replace(Split(StrTmp, "]        [")(0), "[", "")
      StrHi = Replace(Split(StrTmp, "]        [")(2), "]        ", "")
      StrTmp = Split(StrTmp, "]        [")(1)
      ValB = Format((2 * StrLo) - 1, "0000")
      StrNew = "<a href=""#C0RE" & ValB & """>[" & StrLo & "]        </a>"
      StrID = Split(StrTmp, ",")(0)
      ValB = Format((2 * StrID) - 1, "0000")
      StrNew = StrNew & " [<a href=""#C0RE" & ValB & """>" & StrID & "</a>"
      StrID = Split(StrTmp, ",")(1)
      ValA = Format((2 * StrID), "0000")
      ValB = Format((2 * StrID) - 1, "0000")
      StrNew = StrNew & " <a id=""C0RE" & ValA & """ href=""#C0RE" & ValB & """>" & StrID & "</a>"
      StrID = Split(StrTmp, ",")(2)
      ValB = Format((2 * StrID) - 1, "0000")
      StrNew = StrNew & " <a href=""#C0RE" & ValB & """>" & StrID & "</a>]"
      ValB = Format((2 * StrHi) - 1, "0000")
      StrNew = StrNew & " [<a href=""#C0RE" & ValB & """>[" & StrHi & "]        </a>]"
    End If
    .Text = StrNew
NextItem:
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
End Sub
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-23-2012, 06:41 AM   #10
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



it selects and then remove all, even the FIND [] with numbers, nothg remains this way
__________________
newbeeee is offline  
Old 03-23-2012, 11:10 PM   #11
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



You must be doing something wrong - it doesn't do that when I use it.

BTW, when posted here, the forum software inexplicably inserts spaces where there shouldn't be any. There should not be any spaces in any of these strings:
Code:
"]           "
"]           </a>"
"]           ["
Even without those changes, the code won't delete other text.
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-24-2012, 11:44 AM   #12
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



result is the same i dont know where i missed, could u plz send that code in txt attachment for reference.

thanks
__________________
newbeeee is offline  
Old 03-24-2012, 01:41 PM   #13
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



See attached
Attached Files
File Type: doc newbee.doc (50.0 KB, 2 views)
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-25-2012, 09:09 AM   #14
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



tried this one too, but some error

for


[12] jjjjjjjjjjjjjdfgfgjjjjjjjjjjjjjjj [12] jsdsdjjjjjjj [12, 13, 14] ccsdsdccc [12, 13, 14, 15,16]

[12] [1, 22, 12] [1]

in macro at
Code:
 StrHi = Replace(Split(StrTmp, "]  [")(2), "]  ", "")
kindly look into it
__________________
newbeeee is offline  
Old 03-25-2012, 03:14 PM   #15
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



The code works for the example you posted and I have no idea what you mean by "some error". I am not interested in pursuing something so vague, but I do note that the code snippet you posted has spaces where the code I supplied has none.
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-25-2012, 03:22 PM   #16
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



yes it could be like that for code,

if you run the code which you suggested you can see what I was explaining here ,

here is the example which I took

[12] asdfgdfgfgfrth [12] jsdsdgthdgfj [12, 13, 14] ccsdsdccc [12, 13, 14, 15,16]

[12] [1, 22, 12] [1]

for reference
__________________
newbeeee is offline  
Old 03-25-2012, 03:26 PM   #17
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



run time error 9
subscript is out of range
------
Thats the error I got

this is happening only when it finds for
[12, 13, 14]
__________________
newbeeee is offline  
Old 03-25-2012, 03:36 PM   #18
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



Macropod, here what I think is that we make it clear that what ever comes between (that is numbers) gets converted to code,
with following rules:

1. if this is first time it is comming (that is number) then change it in as long format of code,
2. else what ever gets repeated again & again gets into shorter format

let it be how many numbers combination comes inside []

that will make our things easy at both end.

thanks,
__________________
newbeeee is offline  
Old 03-25-2012, 03:39 PM   #19
Moderator
- Microsoft Support
Microsoft MVP

Microsoft Most Valuable Professional
 
Join Date: Apr 2008
Location: Australia
Posts: 1,912
OS: Win 7 (64-bit)



When you asked for additional help, you gave one example:
[12] [1, 22, 12] [1]
for which the required output was:
<a href="#C0RE0023">[12]</a> [<a href="#C0RE0001">1</a> <a id="C0RE0044" href="#C0RE0043">22</a> <a href="#C0RE0023">12</a>] [<a href="#C0RE0001">[1]</a>]

The code I posted handles all such cases. You did not provide any examples (other than for finding strings like [12, 34, 56] and [6, 34, 56, 78]) to suggest what, if anything they need to be replaced with. Those strings are quite unlike the [12] [1, 22, 12] [1] sequence that you did specify.

Your failure to properly specify your requirements means that the effort I have invested in this has been wasted and the code would need to be completely re-written. I have told you twice before that a failure on your part to properly specify the requirements would result in you receiving no further help from me. You have now passed that point.
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 03-25-2012, 03:43 PM   #20
Registered Member
 
Join Date: Feb 2012
Posts: 49
OS: xp sp3, hmmmmmm yes sure



Hi Paul Edstein,

You are very true fr that part that I dont give you proper things in first go, but here I must say that I dont think as you do as programmer, but I try to give you as much as possible ways which I think will help you to get to the solutions.

This is ony the way I can express my thughts apart from programming, so kindly dont take it in other way that I am just wasting your valuable time at all.

Just trying hard to get all things together for you that is it....

Thanks,

__________________
newbeeee is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Association 11
continued from http://www.techsupportforum.com/f289/word-association-10-a-393638.html
Jason Forum Games and Jokes 12343 Today 01:04 PM
Three Word Game 2012
that shall always
turtledove Forum Games and Jokes 5914 01-01-2013 04:01 AM
Excel macro
Hi! How to create a macro for printing some sheets. Like example when I start macro that a message box pops up an ask me for Sheet name or something like that. I tried some macros but i could't get it right :banghead:
tkme15 Microsoft Office support 3 03-17-2012 04:44 AM
Spell check of Word keeps ignoring a paragraph
Hi there, I got this weird problem. First, MS Word did not want to run spell check saying that some component was missing (which was strange because it was working the same day earlier). Anyway, I ran a repair install for MS Office, and then I restarted the computer, and reopened the Word file I...
akofalvi Microsoft Office support 1 03-16-2012 06:09 PM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2


All times are GMT -7. The time now is 04:43 PM.


Copyright 2001 - 2014, Tech Support Forum

Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts