Microsoft Word - Word macro can access outer application with params throught hyperlink

Asked By József Keller on 03-Feb-12 09:44 AM
Hi,

I am using Word 2000.

I develop a new application under MS Word with macros. Word provides the ability of text edition (using Word is compulsory) and each paragraph of the text has a hyperlink to call an outer application to play the wave file belongs to that text. My problem is that some parameters should be given to that outer application (the name of the .wav file the starting and ending timestamps of the .wav file that are in connection with the text paragraph to be examined). How can I give parameters through a file:/// protocol? The hyperlinks can use this protocol to access the outer application. Word MACROS are able to access outer applications (NOTEPAD.EXE), but parameters cannot be given (for example in case of notepad.exe <text_filename>, the notepad.exe will be started without opening the given existing file).

If you had a good idea, it would be appreciated. Thanks for your help.

 Best regards,
Jozsef Keller

Danasegarane Arunachalam replied to József Keller on 03-Feb-12 09:56 PM
From here I can see that the Hyperlink does not support the file name with parameters method. And you could do a work around with the macro button

1. Open the VBA Editor by pressing the ALT+F11 Button
2. Create a small sub to open the macro

Sub OpenNotepad()
  Shell ("notepad.exe C:\Temp.txt")
End Sub
 
'This Tell the winword that open the macro in single button click
Private Sub Document_New()
   Application.Options.ButtonFieldClicks = 1
End Sub

3. Close the VBA Editor
4. And in the Document window Press Ctrl+F9
5. This will place the Macro button tag in the document as
{}


6. Now type the text as



           Where
              MacroButton is the keyword to place the macro button
             OpenNotepad is the MacroName
             Open notepad is the Display Text

7. Now Right Click the Inserted button and select the Toggle field option
8. Now you will see "Click Here to Open NotePad" option
9.Press Ctrl+Shift+S option and from the style select the HyperLink



10. Now you link, Press the button. This will open the Notepad
11. I have use the Shell Function of Word VBA to open External Application


Sample file




Danasegarane Arunachalam replied to József Keller on 03-Feb-12 09:57 PM
Sample missed in previous post.


And here it is

Hyperlinks.zip
Anoop S replied to József Keller on 04-Feb-12 04:10 AM
Refer this example for Opening specified file, and append input to textfile

Sub PrintToTextFile()

Dim FileNum As Integer, cl As Range, z As Integer, y As Integer
Dim myStr As String
FileNum = FreeFile ' next free filenumber
Open "C:\temp\TEXTFILE.TXT" For Append As #FileNum
Print #FileNum, [a1]
z = 10
For Each cl In [b10:f30]
    y = cl.Row
    If y = z Then
      myStr = myStr & "|" & cl
     
'appends the input to an existing file write to the textfile
    Else: Print #FileNum, myStr
      z = cl.Row
      myStr = "": myStr = myStr & "|" & cl
    End If
Next

'appends the input to an existing file write to the textfile

Print #FileNum, myStr
Close #FileNum ' close the file

End Sub
József Keller replied to Danasegarane Arunachalam on 06-Feb-12 06:56 AM
Hi,

Thanks for your help. It works.

Best regards,
József Keller
József Keller replied to Anoop S on 06-Feb-12 07:01 AM
Hi,

My problem was not the same, but this code is useful for me. Thanks.

Best regards,
József Keller