-1

我在一列中有补救票号(例如,HD0000001006530)。

我必须在每个引用自身的单元格上创建一个超链接。单击超链接将运行宏。

宏必须创建一个 .artask 类型的文件,其内容如下所示并打开它。打开 .artask 文件将打开故障单 HD0000001006530 以进行补救。


[快捷方式]
Name = HPD: HelpDesk
Type = 0
Server =remediateprd
Ticket = HD0000001006530 <--- 这个值将来自 excel 单元格

4

1 回答 1

1

在启用宏的 Excel 文件中,将此代码复制到选定的“工作表”代码窗格。

           Private Function Createfile(ByVal cellvalue As String)
            Open "c:\" & cellvalue & ".artask" For Output As #1 'your target file name and address. you may change it to the desired folder
            Print #1, "[Shortcut]"
            Print #1, "Name = HPD: HelpDesk"
            Print #1, "Type = 0"
            Print #1, "Server = remedyprd"
            Print #1, "Ticket =" & cellvalue
            Close #1
           End Function

 'EDIT BEGINS:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Dim cell As Range
 If Dir("C:\" & cellvalue & ".artask") = "" Then 'For memory optimization we should first check if the file exists or not

For Each cell In Range("A1:A" & Me.UsedRange.Rows.Count) 'Specify the Range, in that case it is from A1 to end of the column A
   cell.Select
  ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="c:\" & Selection.Text & ".artask", TextToDisplay:=Selection.Text

    Next cell 'Loop through cells

            Createfile (Selection.Value)
        End If
          End If

      End Sub
    'EDIT ENDS

如果您有任何问题,请告诉我。

于 2013-02-12T11:37:38.020 回答