I am searching for a macro to search a string from worksheet as per given criteria. And it matches the string from another worksheet and paste the picture corresponds to that text. if the string is not found then it should leave that search and search next one. like that i need to do the search string and convert it into pdf file.
here is the sample code
Sub EXCELTOPDF()
Dim strPath As String
Dim strFile, A As String
Dim NextRow As Long
strPath = "C:\Users\919944\desktop\xyz"
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strFile = Dir(strPath & "*.xls", vbNormal)
Do While strFile <> ""
Workbooks.Open strPath & strFile
On Error Resume Next
If (Cells.Find(What:="ABC", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate) Then
ActiveCell.Value = ActiveCell.Value()
ActiveCell.Select
Windows("Image_S.xlsx").Activate
Cells.Find(What:="ABC", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveSheet.Shapes.Range(Array("Picture 123")).Select
Selection.Copy
Windows(strFile).Activate
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
End If
If (Cells.Find(What:="XYZ", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate) Then
ActiveCell.Value = ActiveCell.Value()
ActiveCell.Select
Windows("Image_S.xlsx").Activate
Cells.Find(What:="XYZ", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveSheet.Shapes.Range(Array("Picture 638")).Select
Selection.Copy
Windows(strFile).Activate
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
End if
If (Cells.Find(What:="EFGH", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate) Then
On Error Resume Next
ActiveCell.Value = ActiveCell.Value()
ActiveCell.Select
Windows("Image_S.xlsx").Activate
Cells.Find(What:="EFGH", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveSheet.Shapes.Range(Array("Picture 24")).Select
Selection.Copy
Windows(strFile).Activate
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
End If
If (Cells.Find(What:="PQRS", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate) Then
ActiveCell.Value = ActiveCell.Value()
ActiveCell.Select
Windows("Image_S.xlsx").Activate
Cells.Find(What:="PQRS", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveSheet.Shapes.Range(Array("Picture 23")).Select
Selection.Copy
Windows(strFile).Activate
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
End If
iPtr = InStrRev(ActiveWorkbook.FullName, ".")
If iPtr = 0 Then
sFileName = ActiveWorkbook.FullName & ".pdf"
Else
sFileName = Left(ActiveWorkbook.FullName, iPtr - 1) & ".pdf"
End If
sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, fileFilter:="PDF Files (*.pdf), *.pdf")
If sFileName = "False" Then Exit Sub
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, filename:=sFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
strFile = Dir
Loop
End Sub
In the above example ABC is not found then move the search to next string XYZ. image_s is the worksheet that contains list of pictures related to that name. kindly do the needful
Compiled but not tested: