|
本帖最后由 事后诸葛亮 于 2013-5-2 11:34 编辑
上图是在EXCEL中 插入图片功能时所显示的窗口。
我想:
用VBA模拟出一个插入图片(或文件)的窗口来,
当我选择了照片时,文件名称栏自动填充。
点击 “插入” 按钮时,执行复制动作,把所选择的照片,复制到“C:\照片”目录下。
谢谢了。
- Sub 按钮1_Click()
- Dim srcFile$, DstFile$
- Dim strDstPath$
-
- strDstPath = "C:\照片"
- On Error GoTo ErrorCheck:
- With Application.FileDialog(msoFileDialogFilePicker)
- .Filters.Add "图像文件", "*.jpeg;*.jpg;*.png"
- .AllowMultiSelect = False
- .Show
- If .SelectedItems.Count > 0 Then
- srcFile = .SelectedItems(1)
- DstFile = Mid(srcFile, InStrRev(srcFile, "") + 1)
- DstFile = Left(DstFile, InStrRev(DstFile, ".") - 1) & "-复制" & Mid(DstFile, InStrRev(DstFile, "."))
- Range("a1").Value = srcFile
- FileCopy srcFile, strDstPath & DstFile
- MsgBox "源文件:" & srcFile & vbCrLf & vbCrLf & _
- "目标文件:" & strDstPath & DstFile, vbInformation
- Exit Sub
- End If
- End With
- ErrorCheck:
- MsgBox Err.Number & vbCrLf & _
- Err.Description, vbCritical
- End Sub
复制代码
|
|