• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to check single file is exists in two different folder using VBA macro.

Nitesh Khot

Member
Hi...


I have imagine and wrote below code to check single excel sheet is available in two folder. But code doesn't work.

I want that if condition check that file is exists or not in two folder.
 

Attachments

  • error in code.txt
    1.2 KB · Views: 2
Hi Nitesh,

I have noticed a small mistake in the code I see is the If condition written.

This is currently written as :

Code:
 If Dir(s1)  And Dir(s2) <> "" Then

Try Changing the same as follows and see if this works:

Code:
 If Dir(s1)<>""  And Dir(s2) <> "" Then

Thanks,
Ramesh Kumar.P
 
Hi..thanks for reply....

code is fine but unable to get file name....i want to check file is exists in any one folder if exists then get last two character of file name.

Sub file_prepare()
Dim s1, s2 As String
Dim count1, count2 As String
Dim date1, fileno As String
Dim dir1, dirchngpath1, dir2, dirchngpath2, fileno1 As String

dirchngpath1 = ("C:\Users\nk\Desktop\Data Sync\")
ChDir (dirchngpath1)
dir1 = Dir(dirchngpath1 & "Data_Sounth_" & Format(Date, "DDMMYYYY") & "_ *.xlsx")
s1 = dir1
dirchngpath2 = ("D:\Data_Nk\Sync Data\Data\")
ChDir (dirchngpath2)
dir2 = Dir(dirchngpath2 & "Data_Sounth_" & Format(Date, "DDMMYYYY") & "_ * _" & fileno & ".xlsx")
s2 = dir2

If Dir(s1) <>"" And Dir(s2) <> "" Then
fileno1 = Right(s1, 2) +1

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:="C:\Users\nk\Desktop\Data Sync\Data_Sounth_" & Format(Date, "DDMMYYYY") & "_" & count2 & "_" & fileno1 & ".xlsx" ', FileType:=xlWorkbookNormal
ActiveWorkbook.Close

Else

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:="C:\Users\nk\Desktop\Data Sync\Data_Sounth_" & Format(Date, "DDMMYYYY") & "_" & count2 & "_" & fileno & ".xlsx" ', FileType:=xlWorkbookNormal
ActiveWorkbook.Close

end if

end sub
 
Hi,

I have query about to convert PDF image and text into word or excel format where i can convert pdf text into word or excel format except image which is in text format(readable).
The image is in JPEG format. I have tried many sites but they are not matching the exactly the text is given in PDF.

Please advice.

Amit Singh
 
Back
Top