Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

word 2003 macro help required


(!)

newbeeee's Avatar
newbeeee newbeeee is offline
Computer Specs
Member with 7 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Beginner
17-Feb-2012, 05:08 AM #1
word 2003 macro help required
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
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,186 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
17-Feb-2012, 07:26 PM #2
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
newbeeee's Avatar
newbeeee newbeeee is offline
Computer Specs
Member with 7 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Beginner
17-Feb-2012, 07:50 PM #3
Word 2k3 VBA for number sequence find REPLACE
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
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,186 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
18-Feb-2012, 04:24 AM #4
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.
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,186 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
18-Feb-2012, 04:49 AM #5
Is it correct to assume that for all digits enclosed in [ ] you want the [ and the ] to be removed?
newbeeee's Avatar
newbeeee newbeeee is offline
Computer Specs
Member with 7 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Beginner
18-Feb-2012, 04:57 AM #6
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
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,186 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
18-Feb-2012, 08:30 AM #7
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?
newbeeee's Avatar
newbeeee newbeeee is offline
Computer Specs
Member with 7 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Beginner
18-Feb-2012, 08:43 AM #8
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,
newbeeee's Avatar
newbeeee newbeeee is offline
Computer Specs
Member with 7 posts.
THREAD STARTER
 
Join Date: Feb 2012
Experience: Beginner
18-Feb-2012, 08:45 AM #9
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
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,186 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
18-Feb-2012, 07:26 PM #10
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 & "\*.rtf*")

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
File Type: xls newbeeee-Book1.xls (70.5 KB, 15 views)
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


Tags
word macro 2k3

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑