Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I have taken a Macro that deletes a file and tried to modify it to Move a file, here is what I have, I get no errors, it does not move the file, it just takes me back into the Edit Module screen, any ideas?
FUNCTION MoveFile(mFile)
SET oFile = CREATEOBJECT("Scripting.FileSystemObject")
currentStatus = oFile.FileExists(mFile)
IF currentStatus = TRUE THEN
oFile.MoveFile(mFile)
END IF
SET oFile = Nothing
END FUNCTION
SUB MoveFiles
SET doc = ActiveDocument
SET mySelections = doc.fields("Full Path").GetSelectedValues
FOR i = 0 to mySelections.Count - 1
MoveFile mySelections.Item(i).text, "C:\Users\alan\Desktop\"
NEXT
END SUB
I would rather try something like this:
SUB MoveFile(source, destination)
SET oFile = CREATEOBJECT("Scripting.FileSystemObject")
currentStatus = oFile.FileExists(source)
IF currentStatus = TRUE THEN
oFile.MoveFile(source, destination)
END IF
SET oFile = Nothing
END SUB
SUB MoveFiles
SET doc = ActiveDocument
SET mySelections = doc.fields("Full Path").GetSelectedValues
FOR i = 0 to mySelections.Count - 1
file = mySelections.Item(i).text
call MoveFile(file, "C:\Users\alan\Desktop\")
doc.GetApplication.Sleep 1000
NEXT
END SUB
- Marcus
I would rather try something like this:
SUB MoveFile(source, destination)
SET oFile = CREATEOBJECT("Scripting.FileSystemObject")
currentStatus = oFile.FileExists(source)
IF currentStatus = TRUE THEN
oFile.MoveFile(source, destination)
END IF
SET oFile = Nothing
END SUB
SUB MoveFiles
SET doc = ActiveDocument
SET mySelections = doc.fields("Full Path").GetSelectedValues
FOR i = 0 to mySelections.Count - 1
file = mySelections.Item(i).text
call MoveFile(file, "C:\Users\alan\Desktop\")
doc.GetApplication.Sleep 1000
NEXT
END SUB
- Marcus
Hi Marcus,
That worked perfectly, although I had to remove parentheses from
oFile.MoveFile(source, destination)