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

[SOLVED] MS Word 2007 Macro - tricky auto numbering??

This is a discussion on [SOLVED] MS Word 2007 Macro - tricky auto numbering?? within the Microsoft Office support forums, part of the Tech Support Forum category. Hi, I'm trying to achieve something that i'm not even sure is possible (not a good start) with MS Word


Closed Thread
 
Thread Tools Search this Thread
Old 04-13-2012, 03:41 AM   #1
Registered Member
 
Join Date: Apr 2012
Posts: 4
OS: WinXP



Hi,

I'm trying to achieve something that i'm not even sure is possible (not a good start) with MS Word / macros.

I have a aeospace technical publications company and we work with SGML / XML. In order to hotspot (hyperlink link) item numbers within the text of the document to the item numbers on the graphics in our publications, it's necessary to use hotspot declaration tags in the document. These look like this:

<hotspot id="f001-g001-hot001" apsid="AUTOID_16841" apsname="1">
</hotspot>
<hotspot id="f001-g001-hot002" apsid="AUTOID_25478" apsname="2">
</hotspot>
<hotspot id="f001-g001-hot003" apsid="AUTOID_25479" apsname="3">
</hotspot>
<hotspot id="f001-g001-hot004" apsid="AUTOID_25768" apsname="4">
</hotspot>
<hotspot id="f001-g001-hot005" apsid="AUTOID_25769" apsname="5">
</hotspot>

Sometimes these lists can be several hundred items long.

For generating these tags we can extract the data from the CGM graphic file by using a Word macro which was kindly given to me by another company. We simply put the Word document containing the macro (attached) into the same folder as the Web CGM graphic files, open the Word doc, double click "start", and the macro runs. This in turn generates seperate XML files for each graphic. When we open the resulting XML files in notepad the code has been generated (as seen above) and is ready to be copied and pasted into our document.

However, what the macro doesn't do is to generate the last number in the hotspot id sequence (see above hot001, hot002, hot003 and so on) it simply generates "hot0" and the remaining part of the number has to be entered manually.

The "hot0" number ALWAYS needs to corrolate with the "apsname" number at the end of the string, so if the apsname="5" then it needs to be hot005 (always padded to 3 digits), or apsname=17 would need to be hot017.

Surely there is way of amending our macro so that it pulls the correct number from the apsname at the end, then inserts it at the end of the "hot0" part of the string? This would save a lot of time and prevent having to manually enter the hot0 number for every single item.

Any help would be greatly appreciated

Jake
Attached Files
File Type: doc P3_create_Hotspot_xml.doc (46.5 KB, 17 views)

__________________
JakeMemery is offline  
Old 04-14-2012, 12:41 AM   #2
Moderator
- Microsoft Support
Microsoft MVP

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



Hi Jake,

I suspect what you want can be achieved by changing:
Selection.InsertAfter Text:="<hotspot id=""f001-g001-hot0"" apsid="""
to:
Selection.InsertAfter Text:="<hotspot id=""f001-g001-hot" & Format(i, "0000") & """ apsid="""

Aside from that, though, the code appears to be very inefficient, as it makes extensive use of Selections instead of Range objects.

__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 04-14-2012, 06:23 AM   #3
Registered Member
 
Join Date: Apr 2012
Posts: 4
OS: WinXP



Many thanks for the reply. I have little experience with VBA or macros so what you just said doesn't make a great deal of sense to me, but i will certainly try changing the code to what you suggest and see if that does the trick.

Many thanks again for the pointer.

Jake
__________________
JakeMemery is offline  
Old 04-20-2012, 02:03 AM   #4
Registered Member
 
Join Date: Apr 2012
Posts: 4
OS: WinXP



Hi Macropod,

Thanks again fro your previous reply.

I've amending the line of code as you suggested, and the result would be fine if all the APSNAME numbers in the CGM file were ordered sequencially from 0 upwards. However, they are not always in order (i forgot to meantion this in my original post.)

Therefore, the macro needs to be able to pull the specific APSNAME number from it's respective line and assign it into the "hot" attribute.

See the example below, which is what results from the amended macro:

<hotspot id="f001-g001-hot0000" apsid="'AUTOID_6378" apsname="1"></hotspot>
<hotspot id="f001-g001-hot0001" apsid="'AUTOID_6377" apsname="9"></hotspot>
<hotspot id="f001-g001-hot0002" apsid="'AUTOID_6376" apsname="2"></hotspot>
<hotspot id="f001-g001-hot0003" apsid="'AUTOID_6375" apsname="4"></hotspot>
<hotspot id="f001-g001-hot0004" apsid="'AUTOID_6374" apsname="10"></hotspot>

You can see that the macro has just sequencially numbered the "hot" attribute and padded it correctly, but it needs to pull in the specific "apsname" number from the end of the line.

Is this possible do you think?

Again, I appreciate your input and help.

Jake
__________________
JakeMemery is offline  
Old 04-20-2012, 03:38 AM   #5
Moderator
- Microsoft Support
Microsoft MVP

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



Hi Jake,

In that case, it appears the numbers are being derived from values in your 'hsinfo' array. Try changing your 'If hsinfo(i, 0) <> "grobject" Then ... End If' block to:
Code:
If hsinfo(i, 0) <> "grobject" Then
  Selection.InsertAfter Text:="<hotspot id=""f001-g001-hot" & _
    Format(hsinfo(i, 1), "000") & """ apsid=""" & hsinfo(i, 0) & _
    """ apsname=""" & hsinfo(i, 1) & """></hotspot>" & vbCr
End If
__________________
Cheers
Paul Edstein
[MS MVP -Word]

macropod is offline  
Old 04-20-2012, 04:12 AM   #6
Registered Member
 
Join Date: Apr 2012
Posts: 4
OS: WinXP



Hi Macropod,

That worked a treat! Exactly what i was looking for.

That will save us a lot of time, so thank you very much indeed for your help.

Greatly appreciated.

Jake

__________________
JakeMemery is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:26 AM.


Copyright 2001 - 2014, Tech Support Forum

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