如何插入计数器#excelvba

时间:2019-03-28 09:25:44

标签: excel vba

我从互联网上获得了一个经过修改的宏。此宏基于Excel中的列表而不是源文件夹中的所有文件将文件从一个文件夹复制/移动到另一个文件夹。我的目标是提示用户成功复制了多少文件。

代码如下:

<span id="test" title="foo" data-kind="primary">foo</span>

$("#test").attr("title");
$("#test").attr("data-kind");
$("#test").data("kind");
$("#test").data("value", "bar");

感谢您的帮助

雷伊

1 个答案:

答案 0 :(得分:0)

技巧是在变量中加1,然后在例如消息框中显示此变量

Private Sub CommandButton1_Click()

Dim xRg As Range, xCell As Range
Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
Dim xSPathStr As Variant, xDPathStr As Variant
Dim xVal As String
Dim xCount As Long

ActiveSheet.Range("a4:a5000").Select 'Select active cells

On Error Resume Next
Set xRg = Application.InputBox("Please select the file names:", "Files Selected", ActiveWindow.RangeSelection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
xSFileDlg.Title = " Please select the Source folder:"

If xSFileDlg.Show <> -1 Then Exit Sub
xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
xDFileDlg.Title = " Please select the Destination folder:"

If xDFileDlg.Show <> -1 Then Exit Sub
xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
For Each xCell In xRg
    xVal = xCell.Value
    If TypeName(xVal) = "String" And xVal <> "" Then
        FileCopy xSPathStr & xVal, xDPathStr & xVal
        xCount = xCount + 1
        Kill xSPathStr & xVal
    End If
Next

MsgBox "Task finished. " & xCount & " files were succesfully copied.", vbInformation, "Finished"

End Sub