一个通过VBA建立某文件快捷方式的例子 (备注)

Sub CreatShortCut()
    
    '设定引用项目 Windows Script Host Object Model
    Dim myWsh    As IWshRuntimeLibrary.WshShell
    Dim myShtCut As IWshRuntimeLibrary.WshShortcut
    Dim myPath   As String
    Dim row As Integer
    
    Set myWsh = CreateObject("Wscript.Shell")
    
    For row = 2 To 500
    
        If Cells(row, 1).Value <> "" And Cells(row, 2).Value <> "" And Cells(row, 3).Value <> "" Then
        
            myPath = Cells(row, 3).Value
            
             '指定快捷方式名称
            Set myShtCut = myWsh.CreateShortcut(myPath & "\" & Left(Cells(row, 2).Value, Len(Cells(row, 2).Value) - 4) & ".lnk")
    
            With myShtCut
    
                .TargetPath = Cells(row, 1).Value & "\" & Cells(row, 2).Value                 '指定档案的路径
                '.IconLocation = "c:\tempico.ico"     ‘设定图标
                .Save
        
            End With
            
        Else
        
            Exit For
            
        End If
        
    Next
        
    Set myShtCut = Nothing                      '对象的释放
    Set myWsh = Nothing

End Sub

你可能感兴趣的:(c,windows,object,String,Integer,VBA)