Here are some scripts that will open hyperlinks directly in Microsoft Word, the first script will open all the hyperlinks on a particular page in different tabs on one instance of Internet Explorer. The second script will open individual hyperlinks e.g. "open hyperlink 2" You need to set references to the Microsoft Word object library and Microsoft Internet Controls 1,1. I would be grateful if one of my fellow moderators could test with the German version of DNS and/or convert the scripts accordingly.
(Name the script something like "open all hyperlinks").
1.
'Script by Lindsay Adam, PCByVoice www.pcbyvoice.com Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Dim doc As Document Dim ie As InternetExplorer Dim i Sub Main Set ie = New InternetExplorer For Each doc In Application.Documents For i = 1 To doc.Hyperlinks.Count webpage = doc.Hyperlinks (i).Address ie.Visible = True If i = 1 Then ie.Navigate webpage If i > 1 Then ie.Navigate webpage, 1 Next Next SetForegroundWindow ie.HWND End Sub
The next script will open individual hyperlinks as in the following examples:
2.
"open hyperlink 1" "open hyperlink 3"
Again remember to set the references.
'Script by Lindsay Adam, PCByVoice www.pcbyvoice.com Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Sub Main Dim doc As Document Dim ie As InternetExplorer For Each doc In Application.Documents For i = 1 To doc.Hyperlinks.Count If i = ListVar1 Then Set ie = New InternetExplorer webpage = doc.Hyperlinks (i).Address ie.Visible = True ie.Navigate webpage End If Next Next SetForegroundWindow ie.HWND End Sub
I have also attached the commands in an XML file so you can import directly into the Command Browser. The command names are:
"open all hyperlinks" "open hyperlink " e.g. "open hyperlink 4"
Lindsay, good to read from you and thanks. They both work like the proverbial charm, I copy-and-pasted them and tested them under Office 2007. The only issue was that the first one did not open the links in tabs in the same windows, but in different windows of IE9, but that may be due to some settings of my version.
Cheers, Marius
Dragon NaturallySpeaking 11.5 Legal Windows 7 Prof. 64-Bit, Office 2010, Jarte Plus Philips SpeechMike II Pro Plus, SpeechMike III, SpeechMike Air, PDCC 2.8 Intel Core2 Quad Q9550, 2,83 GHz, 2x6MB L-2, 8 GB RAM
Dateianlage:
Aufgrund eingeschränkter Benutzerrechte werden nur die Namen der Dateianhänge angezeigt Jetzt anmelden!
f12t579p4128n106.xml
thanks a lot for the script and the translation. I would like to use the similar script for hyperlinks in Microsoft Excel. Which lines of the code I need to change and why? I really would like to understand your kind of programming in DNS.
unfortunately all the Microsoft applications have their own individual APIs (application programming Interface) and they are all unique in their own right. Basically there is no fixed pattern between them where you can simply change a couple of commands to get a Microsoft Word macro working in Microsoft Excel.
I am not too familiar with the Microsoft Excel API so without investigating thoroughly I don't know the easy way to open hyperlinks in an Excel document although I am sure it can be done.
If you want to be able to do such things in terms of programming/scripting then the best place to start is with "Larry Allen’s scripting guide" which is available as a paper copy or a PDF copy. We sell either from our website but the shop will not be active until the first of June, if you want to purchase the scripting guide in the meantime then let me know and I can sort it out for you. Larry fixes the prices at exactly the equivalent of US$49, if you buy the paper copy then obviously there will be postage on top of that. Alternatively you can get the scripting guide from various places in America (sorry I don't know if it's available in Germany).
It takes time and lots of patience to learn to program/script to any significant level but the sooner you start the better.
What is being involved here is the so-called VBA (Visual Basic for applications) which comes for Microsoft products such as Word, Excel, Outlook, Internet Explorer etc. As such and being based on Visual Basic, actually being extensions to Visual Basic for each given application, being familiar with the main elements and concepts in Visual Basic certainly will help, but there are a lot of places and ways to start from so it does not really take having been a full-time programmer for years in order to do a few scripts in it. And I would like to show you how and where to start.
To begin with, I would seriously suggest not starting doing VBA scripts from within Advanced Scripting in Dragon NaturallySpeaking, although it is perfectly accommodated to it, but just because it does not really improve your overall understanding of it due to not being the place it has been designed in.
With every of the Microsoft products named above, there is a built in Visual Basic editor which will give you all the functionality you will need to actually test and develop your own scripts, and you will best be off by starting with prefabricated samples which you will find loads of all over the Internet when doing the appropriate searches for it. Therefore, if you are interested in doing something in Microsoft Word, just do a search for "VBA for Word", along with an appropriate keyword according to what you are planning to do. First become a little familiar with using the Visual Basic editor, which should not take longer than 30 min. actually if you do one of the many tutorials you will find.
The most important thing about VBA to understand however is that it incorporates a particular so-called object model for each application which is how the interfaces provided by it are implemented, along with all the rest, what is being referred to as "members", functions, properties, etc. This simply means that if the particular object model provides what you are looking for, it can be done, but it cannot be done if it does not. In addition to that, each object model has a hierarchical structure with all the elements being structured from top to bottom, with branches in various directions, and I am just pointing this out to you to make you aware of that if what you are trying to do does not work from the start it may just be because what you think going from A to B means is more like going from A to C.
One of the implications of being object models however also is that, whenever you create and initiate an object instance, you will also have to take care of dereferencing or deleting it properly, most likely at the end of the code. Therefore, when doing something like
Set ie = New InternetExplorer
Do not forget to do the following at the end of the code
Set ie = Nothing
Sorry Lindsay for having to bring this up, but that is one flaw with the code that you have provided if you ask me, although it will certainly and obviously run – at least for some time. I know it has been your Alzheimer's kicking in.
Finally, since Lindsay also mentioned it, Larry Allen's book of course is one of the most important sources of information as regards Advanced Scripting, and it also contains quite a few things dealing with VBA although this is not what I would buy it for.
And yes, you can get the English version also here in Germany, although places are not easy to find and you will have to pay considerably more than if you were buying in the US or the UK obviously, and also there has been a German translation around for quite a few years which has been provided by Herman Meltzer, one of the members of this forum who used to come posting here before he was made to change his mind and stop doing so.
Have a nice Sunday everyone Rüdiger
_______________________________________
Dragon Professional 16 auf Windows 10 Pro und Windows 11 SpeechMike Premium (LFH3500); Office 2019 Pro + Office 365 (monatliches Abo) HP ZBook Fury 17 G8 - i7-11800H - 24 MB SmartCache - 32 GB RAM - 1 TB SSD
Of course you should always tidy up your objects and incorporate proper error handling and I always do in my normal programming environment, however this involves additional resources and time for just about any script. Considering I am in possession of your performance application source code and have seen many of your scripts in the past you need to practice what you preach you can't just pick on one particular object and say that I haven't dereferenced it, dispose of it properly because there are numerous examples on this forum with the same issue, no unregistering of Dragon objects, no disposing of Dragon objects and the same issue with other Microsoft Outlook objects etc.
Lindsay, no argument over it intended, between you and me, which I wouldn't be in a position to do anyway, being an amateur in the true sense of the word.
Have a nice Sunday Rüdiger
_______________________________________
Dragon Professional 16 auf Windows 10 Pro und Windows 11 SpeechMike Premium (LFH3500); Office 2019 Pro + Office 365 (monatliches Abo) HP ZBook Fury 17 G8 - i7-11800H - 24 MB SmartCache - 32 GB RAM - 1 TB SSD
I don't think we are arguing anyway because you make a very good point, we should all be dereferencing and disposing of objects in the correct manner, in some instances of programming like with the CLR (.NET) some of this is done automatically but not always with the basic scripting engine WinWrap Basic that DNS uses. I think even more important is error handling and very rarely is this provided with scripts on this or any other forums. If I am working in my normal programming environment then I always make sure I incorporate both tidying of objects and error handling, and as you know this is extremely time-consuming and not exactly the most fun part of programming.
Incidentally being lucky enough to be a recipient of some of your current programming investigations with SAPI 4 (I shall say no more than that) I would hardly call you an amateur, as you know I am continually amazed by your progress and you are way ahead of me there.
Thanks for the flattering, oh sorry I meant to say "encouragement". If you are willing to consider someone very often playing by intuition like the deaf dumb and blind kid not being an amateur, and wasting hours to days with the usual trial and error procedures an appropriate way of spending your time, then I am not an amateur.
I just thought that it is worth pointing out that minimally error-checking and taking care of object instances might be a consideration even with the simple scripts. At least I found out the hard way that when the scripts do not work like you would expect them to, this could be it.
Rüdiger
_______________________________________
Dragon Professional 16 auf Windows 10 Pro und Windows 11 SpeechMike Premium (LFH3500); Office 2019 Pro + Office 365 (monatliches Abo) HP ZBook Fury 17 G8 - i7-11800H - 24 MB SmartCache - 32 GB RAM - 1 TB SSD
Just an update on opening hyperlinks in Microsoft Office documents. The following commands all work on just the current instance of Word and not on all Word documents. I expect you can do a similar thing for XL (you will need to do your homework), you just need to assign the active document to the variable doc.Also includes disposing of objects and a modicum of error handling especially for Rüdiger. The script is identical except for the items highlighted in bold. The scripts will additionally differentiate between e-mail hyperlinks and URL hyperlinks.
Command Name: OPEN Hyperlink (application specific to Outlook)
'Script by Lindsay Adam, PCByVoice www.pcbyvoice.com 'Set References to Microsoft Object Library for Outlook and Microsoft Internet Controls Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As _ Long, ByVal nCmdShow As Long) As Long Sub Main Set doc = Application.ActiveInspector.WordEditor Index = Val (ListVar1) If Index (application specific to Word)[/b]
'Script by Lindsay Adam, PCByVoice www.pcbyvoice.com 'Set References to Microsoft Object Library for Word and Microsoft Internet Controls Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As _ Long, ByVal nCmdShow As Long) As Long Sub Main Set doc = ActiveDocument Index = Val (ListVar1) If Index <= doc.Hyperlinks.Count Then webpage = doc.Hyperlinks (Index).Address Dim ie As New InternetExplorer ie.Navigate webpage If Not Mid (webpage, 1, 7) = "mailto:" Then ie.Visible ShowWindow ie.HWND, 9 SetForegroundWindow ie.HWND End If Set ie = Nothing Set doc = Nothing Else MsgBoxConfirm "No such hyperlink",0,"Error opening Hyperlink" End If End Sub