UPDATE 존재하지 않는 경우는 내가 VBA 또는 매크로의 지식이없는 그러나 나는 내 최고의 시도를주지 :의 빈 통합 문서 및 새로운 모듈을 만들어 보자 VBE 다음 코드에서 붙여 넣기, 매크로 사용 통합 문서 (.xlsm)로 저장, 매크로 보안 설정 변경,이 .xlsm 파일을 다시 엽니 다.Excel에서
Alt 키를 누른-F11은 Visual Basic의
삽입을 클릭을 엽니 다 - 모듈>
더블 Module1의 클릭하거나 그냥
붙여 넣기를 만들어 어떤 아래 코드에
Excel에서 다음
Const ForReading = 1
' Change these two below to match your file path
Const KeyWordsFile = "C:\Test\keywordslist.txt"
Const PhrasesFile = "C:\Test\phrases.xlsx"
Sub SO_19150262()
Dim aKeywords As Variant, oWB As Workbook, oWS As Worksheet
Dim R As Long, i As Long, bDelete As Boolean, sTmp As String
Application.ScreenUpdating = False
' Read the Keywords file into aKeywords (array)
aKeywords = GetKeywords(KeyWordsFile)
Set oWB = Workbooks.Open(Filename:=PhrasesFile, ReadOnly:=False)
Set oWS = oWB.Worksheets("Sheet1") ' Change this to match yours
' Start comparing from bottom of used data
For R = oWS.UsedRange.Cells.SpecialCells(xlLastCell).Row To 1 Step -1
bDelete = True
sTmp = "Deleting Row " & R
For i = 0 To UBound(aKeywords)
If Len(aKeywords(i)) > 0 Then
Application.StatusBar = "Checking Row " & R & " for keyword """ & aKeywords(i) & """..."
If InStr(1, oWS.Cells(R, 1).Value, aKeywords(i), vbTextCompare) > 0 Then
sTmp = "Keeping Row " & R & ", Keyword(" & i & "):""" & aKeywords(i) & """"
bDelete = False
Exit For
End If
End If
Next
Debug.Print sTmp
If bDelete Then oWS.Rows(R).Delete
Next
oWB.Save
Set oWS = Nothing
Set oWB = Nothing
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
Private Function GetKeywords(sKeyFile As String) As Variant
Dim aKeys As Variant, oFSO As Variant, oFile As Variant
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(KeyWordsFile, ForReading)
If (oFile.AtEndOfStream) Then
aKeys = Array()
Else
aKeys = Split(oFile.ReadAll, vbCrLf) ' Might need to change to vbCr or vbLf if unix text file
End If
Set oFile = Nothing
Set oFSO = Nothing
GetKeywords = aKeys
End Function
617,451,515,, 저장-으로 -> "엑셀 매크로 사용 통합 문서"
을 개발 도구 탭에서, 나는 당신이 매크로 변화 때문에 서명되지 않습니다 추측 (매크로 보안을 클릭합니다
선택 모든 매크로를 사용)이 모든 매크로를 사용하려면 ... 다음 확인을 클릭합니다
닫고 SO_19150262를 선택하고 클릭이 .xlsm을 다시 열고 개발자 탭에서 매크로 클릭 실행 :
나는 VBA의 길을 가야 할 것이라고 생각한다. 키워드가 별도의 파일에 있거나 통합 문서 내의 별도의 워크 시트에 삽입됩니까? VBA를 작성할 때 차이가 있습니다. –