koffer08 Posted November 12, 2010 Share Posted November 12, 2010 Hey guys, I'm trying to get this code to work for me here, basicly i want it to grab a specif file and move it in a different directory, so basicly from G:\ to C:\ and i dont want to delete it at the end, this one seems to give you the option to choose the file and location then delete it. i want it from one specific file to one specific folder no options and not to delete it. thank you. Sub test()Dim strSelFile As StringDim strNewLoc As StringMsgBox ("Select file to copy")With Application.FileDialog(msoFileDialogFilePicker)If .Show = False Then EndstrSelFile = .SelectedItems(1).AllowMultiSelect = False.Title = "Location to output new file to"End WithMsgBox ("Select location to output file to")With Application.FileDialog(msoFileDialogFolderPicker)If .Show = False Then EndstrNewLoc = .SelectedItems(1).AllowMultiSelect = False.Title = "Location to output new file to"End WithFileCopy strSelFile, strNewLocIf MsgBox("Do you want to delete the source file?", vbYesNo) = vbNo Then Kill (strSelFile)MsgBox ("Done!")End Sub Link to comment Share on other sites More sharing options...
shaffiq_fiq88 Posted February 18, 2011 Share Posted February 18, 2011 Sub test()Dim strSelFile As StringDim strNewLoc As StringMsgBox ("Select file to copy")With Application.FileDialog(msoFileDialogFilePicker)If .Show = False Then EndstrSelFile = .SelectedItems(1).AllowMultiSelect = False.Title = "Location to output new file to"End WithMsgBox ("Select location to output file to")With Application.FileDialog(msoFileDialogFolderPicker)If .Show = False Then EndstrNewLoc = .SelectedItems(1).AllowMultiSelect = False.Title = "Location to output new file to"End WithFileCopy strSelFile, strNewLocIf MsgBox("Do you want to delete the source file?", vbYesNo) = vbNo Then Kill (strSelFile)MsgBox ("Done!")End Sub Quite a mess. Try make it simple. Here a sample. Try to evaluate it.Regarding the "don't want delete." part, I'm quite sure that the problem is within FileCopy function. Try to re-check. Avoid using "With" procedure. Try using only "If...[ElseIf]....End If". Use MsgBox and Exit.... function. Option ExplicitDim GDlg, GPathDim .............Sub GetFileFr()Set GDlg = WScript.CreateObject("Shell.Application")Set GPath = GDlg.BrowseForFolder(&H0, "Select file:", &H4000, 17)If GPath Is Nothing ThenMsgBox "No file selected.", vbOK, "Error"Exit SubEnd IfGetFileFr = GPath.ParentFolder.ParseName(GPath.Title).PathEnd SubSub FileGoTo()'Your codeFileGoTo = FPath.ParentFolder.ParseName(FPath.Title).PathEnd SubSub CopyFileTo(StrFile, StrPastePath)' You CodeEnd SubSub StartCopy() CopyFileTo GetFileFr, FileGoToEnd SubStartCopy() ' or attach to object event as you wish ie:<input value="Copy" type="button" onClick="StartCopy()" /> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.