Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2016, 08:14 AM
vince692 vince692 is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Novice
Get tab_hyperlinks from Word Document
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Question Get tab_hyperlinks from Word Document

Hi,

I am a newbie so every thought will be helpfull ! This is my first vb script...
I'd like to get all hyperlinks into a Word document as table.

Here's my current code de get all hyperlinks :

Quote:
For Each hlien In ActiveDocument.Hyperlinks
With hlien
message = message & .TextToDisplay & .Address & vbCrLf
End With


Next
MsgBox message
My issue is that i need to get only one of the hyperlink. In "message" i got one string with all hyperlink which is not good for me. I want to get the only one i am interesting in.
My thought was instead of getting all hyperlink in one string, getting all hyperlink as table could help me searching special caractere into the tab to get the right index&value.

Hope this is not too foggy.
Any hints will be apreciated !
Best Regards,
Vincent
Reply With Quote
  #2  
Old 05-09-2016, 04:11 PM
macropod's Avatar
macropod macropod is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
With Selection
  If .Hyperlinks.Count > 0 Then
    With .Hyperlinks(1)
      MsgBox .TextToDisplay & vbCr & .Address
    End With
  Else
    MsgBox "No Hyperlink selected"
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-10-2016, 01:15 AM
vince692 vince692 is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Novice
Get tab_hyperlinks from Word Document
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

Hello macropod,

Thanks for your hints but I can't figure out why your attached code is not working.
Problem appears here
With .Hyperlinks(1)

Is it possible to split the result of my "message" generated by my previous code ?
"Message" is attached.
The carriage return could help ?
Then I need to match a string exactly and get the good line...

BR,
Vincent
Attached Images
File Type: jpg Capture.JPG (18.9 KB, 17 views)
Reply With Quote
  #4  
Old 05-10-2016, 01:53 AM
macropod's Avatar
macropod macropod is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your previous post indicated that you want the output for one hyperlink only. The code I posted displays that for any selected hyperlink, with a message box showing the display text on one line and the hyperlink path on the following line. If either of these is too long to display on a single line in the message box, it wraps to the next line. If you want something else, you need to say exactly what that is.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-10-2016, 02:08 AM
vince692 vince692 is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Novice
Get tab_hyperlinks from Word Document
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

.Hyperlinks.Count indicate 0 at runtime whereas i have 3 hyperlink in my WordTest document...
So i got the Else case "No hyperlink selected".

I apologize if i am not clear. Here is my need ;
1 : Get all Hyperlinks name AND Link
2 : Find into previous table HyperlinkName matching exactly "toto"
3 : Get Link associated

This couple of information is gonna be sent as arguments to an exe.
BR,
Vincent
Reply With Quote
  #6  
Old 05-10-2016, 03:35 AM
macropod's Avatar
macropod macropod is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I have already said, the code is for a selected hyperlink. If you don't have a hyperlink selected, the code simply tells you so.

As for the rest or your post, I have no idea what you mean by steps 2 and 3, let alone how you intend to send anything to an exe. You've provided no context for anyone to work with.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-10-2016, 05:03 AM
vince692 vince692 is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Novice
Get tab_hyperlinks from Word Document
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

I'am sorry, i should check it out what you said before. I missed that selection part...
And doing VB for 2 days ...
Your code works great, thank you !

I don't have issue about sending arguments to an exe, i found the shell cmd which is working fine :
Code:
Call Shell("""" & strProgramPath & """" & strArgument & """", vbNormalFocus)
However i need to delete spaces from Hyperlink name to send the name as one argument. I did it and is working fine.

In order to understand .Hyperlinlk is an array of all selected Word hyperlinks ?
Is there a way to work with it or should i create a new variable as myarray() ?

BR,
Vincent
Reply With Quote
  #8  
Old 05-10-2016, 01:35 PM
macropod's Avatar
macropod macropod is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by vince692 View Post
In order to understand .Hyperlinlk is an array of all selected Word hyperlinks ?
No, .Hyperlink is a Hyperlink object - .Hyperlinks is the Hyperlinks collection and .Hyperlinks(#), where # is a number, refers to a particular Hyperlink object from the Hyperlinks collection.
Quote:
Originally Posted by vince692 View Post
Is there a way to work with it or should i create a new variable as myarray() ?
Well, it's quite easy to loop through all the Hyperlink objects in the Hyperlinks collection, which is basically what your original code was doing, but you need to explain what the loop is supposed to achieve - do you just want to get a listing (which your original code does - then sends it to a message box), or do you want to process each hyperlink as it's found, or even do both?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 05-11-2016, 12:24 AM
vince692 vince692 is offline Get tab_hyperlinks from Word Document Windows 7 64bit Get tab_hyperlinks from Word Document Office 2010 32bit
Novice
Get tab_hyperlinks from Word Document
 
Join Date: May 2016
Posts: 22
vince692 is on a distinguished road
Default

I gonna stop to do this search in vba that i don't know because even if you do show me how to get all hyperlinks collection and get the one i am interesting in, it is a code i couldn't maintain further.

I am going to send Documetn Path in argument to my exe and my exe gonna do all the rest.

vba seems to be interesting but i don't have any formation. Will do
Thanks a lot macropod for all your answers.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
Get tab_hyperlinks from Word Document Word document with Macros with trusted locatin versus Word document 1997-2003 Cardinal2 Word 1 11-30-2015 07:42 PM
Get tab_hyperlinks from Word Document How can I link a portion of a word document to another word document and have it auto update? __Data Word 1 06-30-2015 11:03 PM
Get tab_hyperlinks from Word Document Word 2013, changes in word document automatically apply to another word document roosje Word 1 07-09-2014 12:13 PM
Get tab_hyperlinks from Word Document Convert word document to JPEG. The word document may contain headerfooters vijayaram Word 1 12-30-2009 08:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft