Results 1 to 14 of 14
  1. #1
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Macro needed to find "See WP 0100 00" text in doc and link out to source.

    Hello,

    I am in need of a simple macro (I hope) that will:

    1. Point to a folder full of 200 MS Word 2010 (.docx) documents.
    2. Open each document and look for references like: 0100 00
    3. Create a hyper link of that specific numeric sequence (0100 00) to the target document with the same numeric sequence.
    The targeted (linked to) document only has that numeric sequence in the page header and page footer.

    The page header style is called:

    • tmNumber

    The page footer style is called:


    • tmFooter

    If I can get this to work, it will save having to manually find thousands of: See 0100 00 or 0101 00 or 0200 01 types of numeric references.
    The numeric sequence of four digits a space and two digits is a constant, but the last two digits can be 00, 01, or higher. Overall though the sequence is only comprised of 6 digits (4 digits a space and then 2 digits).


    The page footer (tmFooter) style has a field code, but not the page header (tmNumber) style.

    Please see attached screen shots and thanks in advance for any assistance that you can provide. It is really appreciated.

    Regards,

    Jim
    Attached Images Attached Images

  2. #2
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    In response to my posting above, I could reference the physical document name itself with the hyperlinks, using an example like:

    { HYPERLINK "WP0100_00_XYZ_Configuration.docx" }

    but in the end, all these documents will get brought into one single PDF (via Acrobat Pro).

    With that said, if there was a way to get a macro to find the 0100 00 reference for example and then find it again in the header or footer of the targetted document and then somehow link to that targeted header or footer reference, that would be really great, as right now, I have to manually link thousands of links in a string of MS Word documents I received (that will end up in a PDF with working links).

    Thanks for any suggestions or macros that could handle this task.

    Regards,

    Jim

  3. #3
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hello again,

    I have been experimenting with this macro, with two open MS Word documents (side by side).
    First, I have the macro do a find (via CTRL F) and then highlight the reference on the page through the find results window.
    Next I use the Hyperlink button on my toolbar (since I cannot use a mouse when recording a macro).
    Then the hyperlink window opens, but my only option is to point to the physical file name. As mentioned before, I would like to target
    the numeric sequence found in either the header or footer. Does anyone know if this is possible?

    Please see the code below (not much, but it's a start).

    If I cannot get the find and link to the target header or footer, then I would accept the find and link to the target (physical) file name. But again, my first choice is to:

    1. Point to a folder full of MS Word 2010 documents.
    2. Wildcard Find and Replace (CTRL H) a six digit number sequence (four numbers a space and two numbers - e.g. 0100 00).
    3. Close Find and Replace popup window.
    3. Apply the hyperlink option to that selected numeric sequence and reach out to the target document's (which is a separate document) corresponding numeric sequence,
    found in either the header or the footer.
    4. Continue finding through the document (if you will) and then on to the other 200 documents until all documents are linked, saving hours and hours of linking.

    Here is the start of some code, but I don't know how effective it would be, as I have not found a way to target the corresponding numeric sequence in the header or footer, which only appears once, unlike the initial link which be spread over many documents. I need to find a way to reach that unique header or footer reference target.

    Does anyone have any thoughts on this? Thanks again for your suggestions.

    Regards,

    Jim

    See sample code snippet below:


    Sub Macro2()
    '
    ' Macro2 Macro
    '
    '
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "<0***> <**>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    "Test%201.docx", SubAddress:="", ScreenTip:="", TextToDisplay:="0100 00"
    End Sub

  4. #4
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Anyone have any ideas on how to make this macro (if possible)?

    A recap once again. I have a collection of 200 plus MS Word 2010 documents I recieved without hyperlinks. The numeric reference is there, but no link was set.
    I will merge all the documents into a PDF, but first would like to find and turn on all the links, that are just numeric text at this point.


    Therefore, I really need a macro that can:

    1. Point to a folder full of MS Word 2010 documents.
    2. Find the following wildcard numeric sequence: "<0***> <**>" in the body of a document,
    3. Link from that document body reference to the targeted document, where the target location reference (same numeric sequence again) is in the page header or footer of
    the targeted document).

    So, you may have twenty: See 0099 00 references in the body of many documents, but only ONE target document reference and that being in the page header and footer of the destination link.


    Based on that, is it possible to search globally for this wildcard "<0***> <**>" both in the body of the document and the page header or footer?

    It would probably be better to find the footer reference of the targeted instance, as it contains a fieldcode and I could connect the hyperlink to the exact page the link is on, in the source document, based on the field code and page number reference.


    page_footer_target_link.jpg




    Overall this would be a good macro for anyone to have, as you could even put a hidden text style (numeric sequence) in a page header or footer and use that to find the desired location, when hyperlinking between MS Word documents in the same folder.


    So, if anyone has any ideas, please share them, as this is one macro that would be very good to have. And, I need to get a macro like this working (that is if it's even possible).


    Thanks in advance for the suggestions. I look forward to the replies.




    Regards,


    Jim

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Jim,

    I've already sent you a PM about this and your other new threads, which will all require much the same code - code that's already in the previous project that I completed for you. If you can reply to that, maybe we can make some progress ...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Paul,

    I did not see a PM from you on this. Let me go look for it. Thanks,

    Jim

  7. #7
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Paul,

    Yes of course I can reuse the same code from the graphics macro (looping through a folder full of documents). My posting here is really focused on finding the wildcard listed above and linking it to a page header or page footer destination link (another document) when it finds the target. I don't think that segment of coding has been brought up before, at least not that I reckon. Thanks, -J

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Jim,

    With this particular idea, I think you'll find the logic is flawed. That's because, once you merge the documents, all the hyperlinks will continue to point to the pre-merged document via its path rather than as an internal reference. When you create the PDF, all the links in it will continue pointing to the pre-merged document - not to anything within the PDF.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Paul,
    I appreciate your comments about PDFs, but what I am really focused on right now, is finding and linking to keypoints in a header or footer. In theory, I think that is possible to do, I just need to know how to make Word search for a number inside of a footer or header. It could even be a hidden text style or a bookmark that is embedded in the header or footer. That is what I want my origination link to find when it searches through documents. The PDF is another issue and I have other ideas for the MS Word document. Right now my focus is on finding a macro code that can execute that search. If I knew how to do that, I would not be asking it here in this forum. Thanks anyway. Jim

  10. #10
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    How is the target document to be identified?

    On the one hand, you have field coding ({ HYPERLINK "WP0100_00_XYZ_Configuration.docx" }) and macro code (Address:="Test%201.docx") that refer to particular filenames, but you also say:
    The targeted (linked to) document only has that numeric sequence in the page header and page footer.
    If the numeric sequence appears in the filename as indicated in your field code, how is its appearance in the header/footer relevant? If it's not part of the filename, how is one supposed to locate it - by looking through every document's header & footer ranges (bearing in mind there can be three per Section)?

    It's also not apparent how the field code in the footers is relevant, or what part the '{PAGE \* MERGEFORMAT}/2 blank' expression plays.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #11
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Paul,

    Honestly, I never thought it would be this difficult to get a macro. I am about ready to give up on the whole thing. It would seem (at least by you) that I have presented too much information in this posting. So, I will try one last time to post what I am looking for in a new macro. If it can't be done, then tell me and I will end the discussion on this topic here and now (although, the only opinion I have received to date, is from you).

    Okay one last time, I would like to find a macro that:

    1. Points to a folder full of MS Word 2010 documents (this we know already).
    2. Finds a numeric link of six numbers such as: 0100 00 (the format is always the same, starting with a zero, three digits, a space and two digits).
    3. Searches other documents (in the page header or footer only) for the same number, and then establishes a link.
    4. Repeats steps 2and 3 until all numbers in the body of all the documents have links established.

    As for the destination link, yes I agree there can be several header and footer pages, which is why I thought maybe it could link to perhaps a specific footer, such as in page 1, which would contain: '{PAGE \* MERGEFORMAT}/2 . Maybe the code could say, find the first corresponding reference in a footer and link to it.

    Overall, maybe this is not possible to do in MS Word. I am not sure, but since no one else has responded to this post, I am guessing that it's probably not possible to effectively do this in Word.

    Thanks for the input.

    Jim

  12. #12
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Phil,

    it's not a question of how difficult the macro might be to code, or having too much information; it's the clarity of that information that is the issue.

    So, what you want the macro to do is to go through the body of every document, looking for the '0100 00'-type strings and then work out which other document(s) in the same folder have those strings in their header and/or footer and, having done so, insert a hyperlink pointing to the document's relevant header/footer?

    Unless those header/footer strings (at least) are all bookmarked, there's really no practical way to hyperlink to them. And, if there's more than one matching header/footer reference in a given document (eg in a first page header, even page footer in section 1 and an odd page footer in section 2), or in multiple documents, which one should be chosen (a single hyperlink can't target multiple destinations)?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. #13
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Paul,
    So, it looks like I would have to put a unique bookmark in each of the 200 documents first (either through some macro - if possible or manually), in the footer or header. And it looks like linking to
    {PAGE \
    * MERGEFORMAT}/2 might be good in one place where the destination link is for page 1 in a certain document, but not in another, since the destination link may be on page 2 in another case. So, bookmarks are probably the most reliable away to make this happen. I will look into that further. -J

  14. #14
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Phil,

    The macro could easily enough bookmark the '0100 00'-type strings in the headers and footers. However, you haven't addressed my concerns about possible multiple matching header/footer references in a given document, or in multiple documents. If this is a possibility, which one should be chosen (a single hyperlink can't target multiple destinations)?

    There are also other issues with hyperlinking to headers/footers that you need to be aware of, including:
    • doing so opens the relevant page in header/footer view;
    • if the hyperlink is from a source in the same document, it'll hyperlink to the nearest page displaying the bookmarked content in the header/footer. That could mean opening the last header/footer page in a Section, or, if the hyperlink is from a page in the same Section, whatever page the hyperlink is on.
    AFAIK there's nothing you can do to stop a hyperlink doing that in a Word document.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •