dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I have developed some VBA code to move files from a source destination to a target destination.
For example:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Item Code (A1)[/TD]
[TD]File path (B1)[/TD]
[/TR]
[TR]
[TD]AQU10000753.pdf[/TD]
[TD]S:\APS_Logistics\Images\PetsAtHome\03) EXTERNAL CODE IMAGES\HIGH RES - CONTAIN PRODUCTION MARKS!\NOT UPLOADED\[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
The code tells me to click on the cells containing item codes (establishing the name of the target files); thereafter, it asks me to select the range of cells containing the corresponding file paths (in this case, B2).
Then, a dialogue box comes up for me to select the target folder.
The problem is, the code I have is returning a: Run-time error '13' Type mismatch at the following point in red:
Would anybody be able to help me to modify this code please?
Kind regards,
Doug.
I have developed some VBA code to move files from a source destination to a target destination.
For example:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Item Code (A1)[/TD]
[TD]File path (B1)[/TD]
[/TR]
[TR]
[TD]AQU10000753.pdf[/TD]
[TD]S:\APS_Logistics\Images\PetsAtHome\03) EXTERNAL CODE IMAGES\HIGH RES - CONTAIN PRODUCTION MARKS!\NOT UPLOADED\[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
The code tells me to click on the cells containing item codes (establishing the name of the target files); thereafter, it asks me to select the range of cells containing the corresponding file paths (in this case, B2).
Then, a dialogue box comes up for me to select the target folder.
The problem is, the code I have is returning a: Run-time error '13' Type mismatch at the following point in red:
Code:
Sub movefiles()
'Updateby Extendoffice
Dim xRg As Range, xCell As Range
Dim xSFileDlg As Range
Dim xDFileDlg As FileDialog
Dim xSPathStr As Variant, xDPathStr As Variant
Dim xVal As String
Worksheets("UploadImagesHighRes").Activate
'On Error Resume Next
Set xRg = Application.InputBox("Please select the file names:", "Excel tools", ActiveWindow.RangeSelection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Set xSFileDlg = Application.InputBox("Please select the file names:", "Excel tools", ActiveWindow.RangeSelection.Address, , , , , 8)
If xSFileDlg.Show <> -1 Then Exit Sub
xSPathStr = xSFileDlg
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
[SIZE=4][COLOR=#b22222][B] FileCopy xSPathStr & xVal, xDPathStr & xVal[/B][/COLOR][/SIZE]
Kill xSPathStr & xVal
End If
Next
End Sub
Would anybody be able to help me to modify this code please?
Kind regards,
Doug.