Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Is it possible to pass arguments to local hyperlinks to .cmd files?


02 Apr 2012   #1

Windows 7 Professional 64 bit
 
 
Is it possible to pass arguments to local hyperlinks to .cmd files?

I am facing the following interesting situation.

I have an excel file with many columns. One column contains line numbers (for example 3150).

Code:
Source                       Line Number
if(this.getValue()==0)        3150
for(i=0;i<value;i++)           3175
while(true)                       3200
...                                  ...
I want to set up hyperlinks, such that when the user clicks on one of the cells in the Line Number column, a batch program is called with the line number as its command line argument, so that the source file is opened at the specific line number.

I was able to set up a hyperlink without any command line arguments for one cell, but then I had to set the value explicitly in the batch file as follows -

Code:
cd "%~dp0"
notepad++ sourcefile.txt -n3150
So this batch file opens the "sourcefile.txt" at line number 3150 in the Notepad++ editor. However, it's not practical to write a separate batch file for every such line number in the excel sheet. So I am wondering if it is possible to somehow pass the line number as an argument to the batch program.

My System SpecsSystem Spec
.

02 Apr 2012   #2

Windows 8 Core X64
 
 

You can pass a variable to a bath file. Change the line to read

notepad++ sourcefile.txt -n%1
My System SpecsSystem Spec
02 Apr 2012   #3

Windows 7 Ultimate x64
 
 

I could find any information on getting this to work using a hyperlink but I did find a way to do it using some VB code. Took me a little while to get it to work though and it might not be perfect, plus you need to enable macros and remove your hyperlinks.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 3 Then
        Dim strArg As String
        Dim RetVal As Integer
    
        RetVal = MsgBox("Run Batch", vbYesNo)
    
        If RetVal = 6 Then
        strArg = Target
            RetVal = Shell("C:\ExcelExperiments\BatchFile.bat" & " " & strArg, 1)
        End If
    End If
End Sub
This is one example, it runs every time you change the selected cell and first checks if the newly selected cell is in Column C and if it is then it asks you if you want to run the batch file. It needs to be added to each worksheet you want it to work with.

To get to the VBA editor you need to add it to the ribbon by going to,
File > Options > Customize the ribbon and on the right select "Main tabs" and Check "Developer".

Next click the Developer tab on the ribbon and click "Visual Basic". If your using Excel 2003 a quick Google should find a way to do this.

When the editor opens you should see Sheet1,2,3 and ThisWorkbook on the left. Double click a Sheet to open it and then paste my code into it.

Changing the code.
To change the column change Target.Column = 3 to the column number you need, eg. A=1, B=2 etc...

Removing the prompt may prove a problem when entering new data or accidently clicking in the column but if you want to try it then remove the following lines,

1. RetVal = MsgBox("Run Batch", vbYesNo)
2. If RetVal = 6 Then
3. End If ---- Either one


Instead of automatically running you can run it either via a keyboard shortcut or a button.

I really don't know how much you know about this stuff but if you want to set it up as Macro to use a keyboard shortcut or a button and need help or if there's any other problems with this then let me know.
My System SpecsSystem Spec
.


Reply

 Is it possible to pass arguments to local hyperlinks to .cmd files?




Thread Tools



Similar help and support threads for2: Is it possible to pass arguments to local hyperlinks to .cmd files?
Thread Forum
Local HTML files won't load CSS (IE-10) Browsers & Mail
best soft to find pass for Excel 2010 files ?? Microsoft Office
Solved Create a Shortcut with arguments to exe file windows 7 General Discussion
Command-line wildcard arguments - not expanding Software
XP Mode: Software Preview Works On Local Files But Not Files On Win7 Virtualization
Shortcut arguments - How do find them? General Discussion
Deleting Files Out of AppData\Local General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 07:24 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33