Excel Macro to create a file and open it

chandrusvc

New Member
Joined
Feb 12, 2013
Messages
1
I am new to excel macro and VB, pls bare with me.
I have remedy ticket numbers(eg , HD0000001006530) in one column.
I have to create a hyperlink on each cell referencing to itself.Cliking the hyperlink will run a macro.
The Macro have to create a file of type .artask with content like below and open it. Opening a .artask file will open the tikcet HD0000001006530 in remedy.
==============================
[Shortcut]
Name = HPD: HelpDesk
Type = 0
Server = remedyprd
Ticket = HD0000001006530 <--- This value will come from excel cell

Any ideas ?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi and welcome to the forum.

I may be only able to give you a partial solution as I have no means of testing if the output ".artask" file opens the parent program.

From Google, the .artask extension denotes a text file. So here is the code to output a text file with an .artask extension. Fingers crossed...

Assumptions:
We are working with Sheet1.
The cell with the hyperlink only displays the ticket number, i.e., HD0000001006530.
This is the TextToDisplay property.

Press ALt+F11 to open the vba editor window.
Click Insert => Module.
Copy and paste the code below.
Edit where highlighted.
Code:
[COLOR=darkblue]Sub[/COLOR] OutputArtaskTextFile([COLOR=darkblue]ByVal[/COLOR] TicketNumber [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR])
   [COLOR=darkblue]Dim[/COLOR] sPath [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
   [COLOR=darkblue]Dim[/COLOR] fNum [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
   [COLOR=darkblue]Dim[/COLOR] sOutput [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
   
   sPath = "[COLOR=#ff0000]C:\temp[/COLOR]\" & TicketNumber & ".artask"
   
   sOutput = "==============================" & vbCrLf _
         & "[Shortcut]" & vbCrLf _
         & "Name = HPD: HelpDesk" & vbCrLf _
         & "Type = 0" & vbCrLf _
         & "Server = remedyprd" & vbCrLf _
         & "Ticket = " & TicketNumber


   [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] errExit
   
   fNum = FreeFile
   [COLOR=darkblue]Open[/COLOR] sPath [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Output[/COLOR] [COLOR=darkblue]As[/COLOR] #fNum
      [COLOR=darkblue]Print[/COLOR] #fNum, sOutput
   [COLOR=darkblue]Close[/COLOR] #fNum


errExit:
   [COLOR=darkblue]Close[/COLOR] #fNum
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]


Double click the Sheet1 module in the Project Window on the left hand side.
Copy and paste the code below.
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_FollowHyperlink([COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Hyperlink)
   Module1.OutputArtaskTextFile Target.TextToDisplay
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]


Go back to Excel and click the hyperlink and test the output file.

Hope this helps,
Bertie

 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top