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
SmartShark

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
Ztruker

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
Duzzy

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
Thread Forum
'Some files can contain viruses' warning when clicking on hyperlinks
It is very useful to be able to open files referred to in Excel files via a hyperlink to the file itself. In many xslx files (Office 2007) this works fine. In others I get a warning message (with blue question mark) asking me if I really want to open the file. I can't see what makes one Excel file...
Microsoft Office
best soft to find pass for Excel 2010 files ??
best soft to find pass for Excel 2010 files ?? my Uncle create very important programs on Excel 2010 which tooks over 1-2 months to create but now they forgot its password I want to break its pass to help them
Microsoft Office
Create a Shortcut with arguments to exe file windows 7
I was trying to add a few shortcuts to my Windows 7 Start Menu and add a command line argument to the short cut. I was able to create a shortcut for "Windows Explorer" using C:\Windows\explorer.exe /n, /e D:\When I tried to create a shortcut for FireFox to select the profile...
General Discussion
Shortcut arguments - How do find them?
Hello I've googled around the web and this forum without much luck... I'm tryin to find a list of the arguments possible of use when creating shortcuts. I know each application will have it's own list, but i believe there's also a set of arguments for windows functions (like force focus to...
General Discussion
Task Scheduler Error message “…arguments are not valid.”
in Task Scheduler: when I select a task, Properties, then click the button (whether OR NOT I have made any changes), I get an error message: “An error has occurred for task SyncBackSE Mirror Satellite to House D. Error message: One or more of the specified arguments are not valid.” This is...
Performance & Maintenance
Adding program with arguments to Media Center Studio
Evening all. I've found this place to be of great help in the past, and haven't had the need to ask for help until now. Simple setup: LCD TV connected via VGA, LCD Projector connected via HDMI. 2 individual desktops setup with different resolutions. Requirement: I needed a way to switch...
Media Center

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 11:41.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App