1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

word 2003 macro help required

Discussion in 'Software Development' started by newbeeee, Feb 17, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. newbeeee

    newbeeee Thread Starter

    Joined:
    Feb 17, 2012
    Messages:
    7
    Hi

    I have this logic with me and looking to get word macro programmed out of it, but as non programming knowledge it seems out of reach....

    Here is the logic

    Find a digit within [] (any number of digits)
    Copy what is inside of [] and store that as a Temp value
    A=temp x 2
    B= A-1
    <XXX_B><XXX_A>Temp<XXX>


    KINDLY suggest
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    Hi newbee, welcome to the forum

    Where are the [ ] ?
    Are there more than one groups of [ ] ?
    Which one?
    Why not attach a word file as example showing what you have and what you want / need?
    Fill it with non private or dummy data.

    A 'picture' tells more than XXX words :)
     
  3. newbeeee

    newbeeee Thread Starter

    Joined:
    Feb 17, 2012
    Messages:
    7
    My bad:

    Here is an explanation in brief:

    I have a htm file

    <p><span>This study explored student perceptions of the software usability. More usability studies, which[1] can identify why some tools had never been used, why some tools had been used more[12] than others, and how learners actually interacted with these tools, will be required for further adjustment[125] and improvement of the software. These further[12] studies will be able to provide more[325] detailed information regarding[12] how much and[125] how well the software has been used.</span></p>

    Code:
    now here it is required to 
    first find the digits inside [] (as in example say [1] or [12] etc
    then 
    replace 
    it with 
    
    [<a id="C0RE0001" href="#C0RE0002">1</a>]
    
    i.e for [1] 
    for [325]
    <a id="C0RE0649" href="#C0RE0650">325</a>
    ----------
    I got the codes till here .....

    Code:
    but the main issues are coming in here is that if [324] gets repeated in a documents more then once, the very second should be trimmed to 
    
    <a href="#C0RE0648">324</a> 
    -------
    Say we have <a id="C0RE0647" href="#C0RE0648">324</a> repeated 2 to 3 time, 
    we keep the very first as
    
    <a id="C0RE0647" href="#C0RE0648">324</a> 
    
    and the 2nd and 3rd gets like
    
    <a href="#C0RE0648">324</a> 
    <a href="#C0RE0648">324</a> 
    
    --------------------
    Logic here would be to get a TAG first
    compare from start of document
    Leave the 1st one as it is) go to next
    Trim it
    go to next ......till end.
    -----------------
    2 ways it could be done...

    1. manually
    2. If we make a dummy excel file where we generate a sequence of TAGS first,
    then word picks one after the other and get on with comparison till last....(I have an idea but not sure if this communication between is possible or not)

    (As I tried my hands on IMacros a tool which interacts with excel to get a value inside web page)

    Its getting heavy here
     
  4. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    Okay, it's clear.
    Check a post by dmoonglow (in Business Applications) where I helped, I'll try that technique too, Word and Excel and Excel as source, but can be the other way around.
    I think Excel -> Word will make it easier to collect data but that's my personal view.
    I'll see if I can put something together sometime this weekend.
    It's a little tight with appointments and so, but I'll keep you posted.
     
  5. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    Is it correct to assume that for all digits enclosed in [ ] you want the [ and the ] to be removed?
     
  6. newbeeee

    newbeeee Thread Starter

    Joined:
    Feb 17, 2012
    Messages:
    7
    NO, only those if found repeated, say <a id="C0RE0647" href="#C0RE0648">324</a> comes in different places of a document,

    Then VERY first from starting of document, will remain as it is , and the very next and till end will change or gets trimmed.

    ----------------------------
    I am also trying to get code this by the time you put your efforts :) thanks
     
  7. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    Let's see if I get this straight:
    In the sample text above the first code block the [12] appears 3 times
    The first will then be replaced with:
    Code:
    [<a id="C0RE0001" href="#C0RE0002">12</a>]
    
    And the next two or more with

    Code:
    [<a href="#C0RE0002">12</a>]
    
    You keep the brackets but replace what's in between them?

    These #C0RE0001 and #C0RE0002 is there any system in this that has to be kept in mind?
     
  8. newbeeee

    newbeeee Thread Starter

    Joined:
    Feb 17, 2012
    Messages:
    7
    I have used this
    Code:
    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
        placetags = "<a id=" & quote & "C0RE" & ID & quote & " href=" & quote & "#C0RE" & href & quote & ">" & x & "</a>"
    Else
        'short form
        placetags = "<a href=" & quote & "#C0RE" & href & quote & ">" & x & "</a>"
    
    this is working to a way.....

    i will explain here

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

    C0RE0023
    n
    C0RE0024

    are temp x 2 and temp-1 values
    and temp is what is inside [] here that is 12

    Thanks,
     
  9. newbeeee

    newbeeee Thread Starter

    Joined:
    Feb 17, 2012
    Messages:
    7
    NEW Query:

    here is a quick query

    How to move and change a text and digits,

    eg:

    Find a text or word Equation in a para,
    then change it
    and then search next

    eg is


    Code:
    This is as an test for a Equation 1.1.2 and Equation 1.22 and Equation 25.2.35 for a regular formula .................
    
    Output as


    Code:
    This is as an test for a <xxxx_0112>Equation 1.1.2<zzzz> and <xxxx_0122>Equation 1.22<zzzz> and <xxxx_2523>Equation 25.2.3<zzzz> for a regular formula .................
    
    means what ever is after Equation it gets copied and move inside with out dot in it

    i know switch could be used here like \1\2 etc but removing dot is an issue here.....kindly suggest
     
  10. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    I don't quite get the second query.
    For the first part of your post (even if you already solved it) I changed the macro I wrote for dmoonglow a little.
    The macro filters for rtf files, it you want to search other wordlike extensions (doc files) you'll have to edit the corresponding line of code

    Code:
    fArray = GetFileList(wdFilePath & "[COLOR="Red"]\*.rtf*[/COLOR]")
    

    All this macro does is search in the indicated rtf file (the one you answer YES to at the dialog prompt ) is search for all [ and ] by order of search and 'write' the starting posiotions of the [ in column A, the first ] after the previous [ in column B and the text inbetween these two brackes it column C for the entire document.

    You could use this to then change either manually of with a new macro to change and replace the text back into the rft file using the starting position and for the [ as orientation poitn.

    The only thing is when you want to update the word file you'll have to do if from the end back or else the start9ing positions won't comply anymore.

    Will need more code to do all this but maybe you can put this macro to good use for other search and replace
     

    Attached Files:

  11. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1041458