Home > Software engineering >  A very small VBA program, trouble you help me take a look at code where is wrong
A very small VBA program, trouble you help me take a look at code where is wrong

Time:09-28

With employee information in the excel table, I need to C column line 10884 to the last line of the commonly used data with the D disk directory file folder compare the pictures of a lot of information, if the same, then delete the D dish common folder of files, the following my train of thought, the first disk directory traversal traversal D common folder all the photo file name information into the ar array, and then traverse excel column C 10884 lines to all the data in the last row to xls_ar array, and then use a dictionary, add xls_ar array of data, and the inside of the ar through the exists methods comparison, if the same, is to delete operation, the code is as follows:
Sub the delete ()
Dim xlsfile, ar (), n %
Dim xls_ar ()
Xlsfile=Dir (" D: \ common file \ "& amp; "*.jpg")
Do Until Len (xlsfile)=0
N=n + 1
ReDim Preserve ar (1 To n)
Ar (n)=xlsfile
Xlsfile=Dir
Loop

Xls_ar=Range (C10884: "C" & amp; [C65535]. End (3). The Row)
Dim c
The Set dic=CreateObject (" scripting. The dictionary ")
For Each c In xls_ar
Dic (c)=""
Next
For I=1 To UBound (ar) - LBound (ar) + 1
If dic. The exists (ar) (I) Then
Dim filename As String
Filename=Dir (" D: \ common file \ "& amp; Ar (I) & amp; ". JPG ")
Kill "D: \ common file " & amp; Filename
Filename=Dir
End the If
Next
End Sub

My confusion is the filename=Dir (" D: \ common file \ "& amp; Ar (I) & amp; ". JPG ")

Because the program won't be able to identify ar (I) he will go to find the variable name ar (I), rather than the value of the inside, it's strange
I don't know whether this need references or something? Please god to give me some advice and help, I started learning VBA today

CodePudding user response:

Ar (I) have the suffix. JPG, in your filename=Dir (" D: \ common file \ "& amp; Ar (I) & amp; ". JPG ") one more time. JPG
  •  Tags:  
  • VBA
  • Related