0
我可以讓我的代碼打開選定的單元格PDF。我如何循環這個從A9 to finalrow
運行?這是我的工作,但僅限於選定的單元格。excel循環直通單元打開pdf
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
問題出在哪裏? – amg
@amg不確定。它不循環。只打開第一個PDF。我在想它是因爲活動程序改變爲PDF。我能否在某處添加',vbNormalNoFocus'來保持Excel的活動程序。 –
你沒有更新循環內部的'pdfPath'。看到我的回答 – user3598756