自动创建文件的快捷方式

时间:2015-10-19 08:03:58

标签: excel vba excel-vba

我在命令按钮下单击了一小段代码,在新位置保存了新名称的工作簿文件,我想知道是否可以自动创建一个新保存的工作簿的快捷方式位置?

Private Sub CommandButton1_Click()
Dim SelectedFNumber As String
Dim DateStr As String
Dim myFileName As String
Dim StorePath As String

    DateStr = Format(Now, "dd.mm.yy HH.mm")

    SelectedFNumber = Range("B4").Text

    If SelectedFNumber <> "SELECT F NUMBER" And Range("D11") > "0" Then

        StorePath = "G:\Targets\" & SelectedFNumber & "\"

        myFileName = StorePath & SelectedFNumber & " " & DateStr & ".xlsm

        If Len(Dir(StorePath, vbDirectory)) = 0 Then
        MkDir StorePath
        End If

        ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Else
        MsgBox "Select an F Number"
    End If
End Sub

1 个答案:

答案 0 :(得分:2)

你基本上需要添加这样的东西:

Dim sShortcutLocation As String

sShortcutLocation = "C:\blah\workbook shortcut.lnk"

With CreateObject("WScript.Shell").CreateShortcut(sShortcutLocation)
    .TargetPath = myFileName
    .Description = "Shortcut to the file"
     .Save
End With

将位置更改为您想要的位置。