VBA Dir File Copy and Paste: Check if file exists then copy file from one directory to another. Bat File
VBA Copy and Paste: Check if file exists then copy file from one directory to another
vba is placed in a seperate file
and the file which we have to copy is located in C:\Users\WolfieeeStyle\Desktop\Files and the file name is 1.xlsx
so we have to copy that file and paste it to (C:\Users\WolfieeeStyle\Desktop\save it) this location only if file is not present
and if file is present in (C:\Users\WolfieeeStyle\Desktop\save it) this location then we have to copy and paste the file to C:\Users\WolfieeeStyle\Desktop\save it\New folder
so plz help me in solving this problem sir
copy paste a file if its not present & if its present then do nothing
my file name is 4.xlsx
i have to copy this file and paste it to another path( if 4.xlsx file doesn't exist then copy paste it to C:\Users\WolfieeeStyle\Desktop/sholtan , but if file is there in the path C:\Users\WolfieeeStyle\Desktop/sholtan then do nothing)
i want to do this by vba so plz have a look sir and help me in solving this problem sir
file is located at C:\Users\WolfieeeStyle\Desktop/4.xlsx and we have to copy this file and paste it to C:\Users\WolfieeeStyle\Desktop/sholtan
Macro Modifcation if file is not present macro will not do anything
Hi
Code:
Sub STEP12()
Dim Val As String, wb1 As Workbook, wb2 As Workbook, srcWS As Worksheet, desWS As Worksheet
Dim i As Long, v1 As Variant, v2 As Variant, rngList As Object
Set wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\ap.xls")
Set wb2 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\Files\AlertCodes.xlsx")
Set desWS = wb1.Worksheets.Item(1)
Set srcWS = wb2.Worksheets.Item(1)
v1 = desWS.Range("E2", desWS.Range("E" & desWS.Rows.Count).End(xlUp)).Value
v2 = srcWS.Range("A2", srcWS.Range("A" & srcWS.Rows.Count).End(xlUp)).Resize(, 2).Value
Set rngList = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(v1, 1)
Val = v1(i, 1)
If Not rngList.exists(Val) Then
rngList.Add Key:=Val, Item:=i + 1
End If
Next i
For i = 1 To UBound(v2, 1)
Val = v2(i, 1)
If rngList.exists(Val) Then
desWS.Cells(rngList(Val), 25) = v2(i, 2)
End If
Next i
Application.ScreenUpdating = True
wb1.Save
wb2.Save
wb1.Close
wb2.Close
End Sub
This is the macro
I need a slight change in it
If ap.xls files is present then only this macro will work & if ap.xls file is not present then it should not do anything
I can use on error resume next code in this macro but u have suggested not to use that
So i need help for the same
Conditionally Run & move the .bat file shortcut(i.e .lnk file) by vba macro
Hi Experts,
Code:
Public Declare PtrSafe Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Sub FFF()
Dim strFileName As String
Dim strFileExists As String
strFileName = "C:\Users\WolfieeeStyle\Desktop\Close Excel.lnk"
strFileExists = Dir(strFileName)
If strFileExists = "" Then
Set FSO = CreateObject("scripting.filesystemobject")
FSO.MoveFile Source:="C:\Users\WolfieeeStyle\Desktop\Close Excel.lnk", Destination:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\"
ShellExecute 0, "OPEN", "C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\Close Excel.lnk", "", "", 1
Else
End If
End Sub
I am looking for a macro that will
First Check Close Excel.lnk is located or not & if it is located then move that Close Excel.lnk to C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\ & then run that Close Excel.lnk
& If the Close Excel.lnk file is not located then do nothing
This macro is not working i think it has issues
Thnx
https://www.vbforums.com/showthread....)-by-vba-macro
https://chandoo.org/forum/threads/co...a-macro.44815/
https://www.excelforum.com/excel-pro...ml#post5378034
https://www.ozgrid.com/forum/index.p...-by-vba-macro/
Macro Correction(If condition met then do something & if not then do nothing)
“Moderator” Notice
September 2020
Given up with this “OP” , Avinash around September 2020. https://excelfox.com/forum/showthrea...ll=1#post14972
https://excelfox.com/forum/showthrea...ll=1#post14972
I am no longer monitoring what its doings. It had curiosity appeal for a while, but even that has worn off me now!
It’s getting worse by the Day. Its still doing whatever it is that it is doing and getting Replies and answers at excelforum.com and likely a few places I don’t know about.
Hi Experts,
Code:
Option Explicit
Sub STEP2()
Dim wkb As Workbook
Set wkb = Workbooks.Add
wkb.SaveAs Filename:="C:\Users\WolfieeeStyle\Desktop\FALSEFALSEFALSE.xlsx"
wkb.Close
Dim fso As Object
Dim strFileName As String
Dim strFileExists As String
Set fso = CreateObject("scripting.filesystemobject")
strFileName = "C:\Users\WolfieeeStyle\Desktop\FALSEFALSEFALSE.xlsx"
strFileExists = Dir(strFileName)
If strFileExists > "" Then
fso.movefile Source:="C:\Users\WolfieeeStyle\Desktop\FALSEFALSEFALSE.xlsx", _
Destination:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\FALSEFALSEFALSE.xlsx"
Shell "taskkill /F /IM EXCEL.EXE"
Else
End If
End Sub
This macro does what i want & I need a confirmation that this macro is perfect & it has no errors & if there is anything which needs to be modified then plz modify the same & let me know
Thnx
Cross Post
https://eileenslounge.com/viewtopic....273280#p273280
3 Attachment(s)
move the file if condition met
Hello Guys,
If column M data of ap.xls matches with column A data of sample2.xlsx (sheet2) (May be Column M data will be blank or 0 so ignore that)& column G data of oo.xlsx matches with column A data of sample2.xlsx (sheet2) then move the file C:\Users\WolfieeeStyle\Desktop\sample5.xlsx to C:\Users\WolfieeeStyle\Desktop
Macro will be placed in a seperate file macro.xlsm
(Number will be positive or negatiove , No issue with the positive or negative , the number should be present is must)
Thnx Alot