2017-03-29 1 views
0

선택한 코드를 열려면 코드를 가져올 수 있습니다. A9 to finalrow에서이 코드를 반복 실행하려면 어떻게해야합니까? 이것은 내가 선택한 세포에 대해서만 작용하는 것이다. 문제는 어디셀을 통해 Excel에서 루프를 열어

Function OpenAnyFile(strPath As String) 
Set objShell = CreateObject("Shell.Application") 
objShell.Open (strPath) 
End Function 

Sub Cutsheets() 
Application.ScreenUpdating = False 
On Error GoTo whoa 

Dim ordersheet As Worksheet 
Dim I As Integer 
Dim finalrow As Integer 
Dim pdfPath As String 
Set ordersheet = Sheet1 

finalrow = Cells(Rows.Count, 1).End(xlUp).Row 
pdfPath = "P:\ESO\1790-ORL\OUC\_Materials\Material Cutsheets\" & ActiveCell & ".pdf" 

'loop through the rows to find PDFs 
For I = 9 To finalrow 
    If Cells(I, 1) = Application.Intersect(ActiveCell, Range("A9:A" & finalrow)) Then 
    Call OpenAnyFile(pdfPath) 
    End If 
    ordersheet.Select 
Next I 

whoa: 
Exit Sub 

Application.ScreenUpdating = True 
End Sub 
+1

입니까? – amg

+0

@amg 확실하지 않습니다. 루프되지 않습니다. 첫 번째 PDF 만 열립니다. 나는 활성 프로그램이 PDF로 바뀌기 때문에 그것을 생각하고있다. Excel을 활성 프로그램으로 유지하기 위해', vbNormalNoFocus'를 어딘가에 추가 할 수 있습니까? –

+1

당신은 루프 안에서'pdfPath'를 업데이트하지 않습니다. 내 대답을 참조하십시오 – user3598756

답변

3
Sub Cutsheets() 
    Application.ScreenUpdating = False 
    On Error GoTo whoa 

    Dim I As Integer 
    Dim finalrow As Integer 
    Dim pdfPath As String 

    'loop through the rows to find PDFs 
    With Sheet1 
     finalrow = .Cells(.Rows.Count, 1).End(xlUp).Row 
     For I = 9 To finalrow 
      pdfPath = "P:\ESO\1790-ORL\OUC\_Materials\Material Cutsheets\" & Cells(I, 1).Value & ".pdf" 
      Call OpenAnyFile(pdfPath) 
     Next I 
    End With 

whoa: 
    Application.ScreenUpdating = True 

End Sub 
+0

완벽한 작품, Thx 순전히. –

관련 문제